{"id":2519,"date":"2012-01-19T23:09:41","date_gmt":"2012-01-19T23:09:41","guid":{"rendered":"https:\/\/supportex.net\/?p=2519"},"modified":"2019-05-10T17:24:21","modified_gmt":"2019-05-10T15:24:21","slug":"nginx-fcgiwrap-deployment-cgi-applications","status":"publish","type":"post","link":"https:\/\/supportex.net\/blog\/2012\/01\/nginx-fcgiwrap-deployment-cgi-applications\/","title":{"rendered":"nginx: Using fcgiwrap for CGI applications deployment"},"content":{"rendered":"<p>From the box nginx doesn&#8217;t support CGI applications deployment since CGI is very old and poor performance way to run them. But some applications still should be deployed with use of CGI (earlier, we covered setup of <a href=\"https:\/\/supportex.net\/blog\/2011\/11\/migration-nagios-apache-nginx\/\">Nagios<\/a> and <a href=\"https:\/\/supportex.net\/blog\/2011\/11\/migrating-otrs-apache-nginx\/\">OTRS<\/a> with nginx). Here is another way to do that. In this case we will use <a href=\"http:\/\/localdomain.pl\/wiki\/FcgiWrap\">fcgiwrap<\/a> tool by Grzegorz Nosek. It&#8217;s written in C and should provide better performance in comparison with pure Perl wrapper we use before.<\/p>\n<p>Firstly we need install it. If you use Debian or Ubuntu just install if with <em>apt-get<\/em>:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">aptitude install fcgiwrap<\/code><\/p>\n<p>For Fedora we&#8217;ll need compile it from sources. Download fcgiwrap from <a href=\"http:\/\/github.com\/gnosek\/fcgiwrap\/tarball\/master\">Github<\/a> and unpack. Install <em>fcgi-devel:<\/em><\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">yum install fcgi-devel<\/code><\/p>\n<p>Then run:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">make install<\/code><\/p>\n<p>Now you should have <em>fcgiwrap<\/em> installed in \/usr\/local\/bin\/. So, we can proceed with nginx. Here is a sample configuration. As you can see all .cgi files will be considered as CGI applications.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">server {\nlisten 80;\nserver_name example.com;\nroot \/home\/web;\nindex index.html index.cgi;\nerror_log \/var\/log\/nginx\/error.log;\naccess_log \/var\/log\/nginx\/access.log main;\n\nlocation \/ {\nroot \/home\/web;\nindex index.html index.htm;\n}\n\nlocation ~ ^\/cgi-bin\/.*.cgi$ {\nfastcgi_pass unix:\/var\/run\/nginx\/cgiwrap-dispatch.sock;\nfastcgi_index index.cgi;\nfastcgi_param SCRIPT_FILENAME \/home\/web\/$fastcgi_script_name;\nfastcgi_param QUERY_STRING $query_string;\nfastcgi_param REQUEST_METHOD $request_method;\nfastcgi_param CONTENT_TYPE $content_type;\nfastcgi_param CONTENT_LENGTH $content_length;\nfastcgi_param GATEWAY_INTERFACE CGI\/1.1;\nfastcgi_param SERVER_SOFTWARE nginx;\nfastcgi_param SCRIPT_NAME $fastcgi_script_name;\nfastcgi_param REQUEST_URI $request_uri;\nfastcgi_param DOCUMENT_URI $document_uri;\nfastcgi_param DOCUMENT_ROOT $document_root;\nfastcgi_param SERVER_PROTOCOL $server_protocol;\nfastcgi_param REMOTE_ADDR $remote_addr;\nfastcgi_param REMOTE_PORT $remote_port;\nfastcgi_param SERVER_ADDR $server_addr;\nfastcgi_param SERVER_PORT $server_port;\nfastcgi_param SERVER_NAME $server_name;\n}\n}<\/pre>\n<p>At this step we need some way to spawn our FCGI wrapper instances. For that we will use <em>spawn-fcgi<\/em>:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">spawn-fcgi -u web -g web -M 0775 -F 10 -s \/var\/run\/nginx\/cgiwrap-dispatch.sock -U web -G web \/usr\/local\/bin\/fcgiwrap<\/code><\/p>\n<p>To use it we will also need some kind of init.d script. Modern versions of Fedora ship with <em>systemd<\/em>, so we can use it for managing of FCGI instances pool:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">[Unit]\nDescription=spawn-perl-fcgi\n\n[Service]\nExecStart=\/usr\/bin\/spawn-fcgi -u web -g web -M 0775 -F 10 -s \/var\/run\/nginx\/cgiwrap-dispatch.sock -U web -G web \/usr\/local\/bin\/fcgiwrap\nType=forking\nUser=root\nGroup=root\nRestart=always\n\n[Install]\nWantedBy=multi-user.target<\/pre>\n<p>Put in in \/lib\/systemd\/system\/spawn-perl-fcgi.service and run:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">systemctl enable spawn-perl-fcgi.service<\/code><\/p>\n<p>For other systems you can use script <a href=\"http:\/\/wiki.nginx.org\/FcgiwrapDebianInitScript\">provided<\/a> in nginx wiki.<\/p>\n<p>This is it.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>From the box nginx doesn&#8217;t support CGI applications deployment since CGI is very old and poor performance way to run them. But some applications still should be deployed with use of CGI (earlier, we covered setup of Nagios and OTRS with nginx). Here is another way to do that. In this case we will use&hellip; <\/p>\n<div class=\"readmore-wrapper\"><a href=\"https:\/\/supportex.net\/blog\/2012\/01\/nginx-fcgiwrap-deployment-cgi-applications\/\" class=\"more-link\">Read <\/a><\/div>\n","protected":false},"author":4,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[152],"tags":[275,255],"class_list":["post-2519","post","type-post","status-publish","format-standard","hentry","category-linux","tag-linux","tag-niginx"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>nginx: Using fcgiwrap for CGI applications deployment &#8211; Supportex.NET blog<\/title>\n<meta name=\"description\" content=\"How to use fcgiwrap for CGI applications deployment in nginx. Nginx fcgiwrap for CGI applications\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/supportex.net\/blog\/2012\/01\/nginx-fcgiwrap-deployment-cgi-applications\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"nginx: Using fcgiwrap for CGI applications deployment &#8211; Supportex.NET blog\" \/>\n<meta property=\"og:description\" content=\"How to use fcgiwrap for CGI applications deployment in nginx. Nginx fcgiwrap for CGI applications\" \/>\n<meta property=\"og:url\" content=\"https:\/\/supportex.net\/blog\/2012\/01\/nginx-fcgiwrap-deployment-cgi-applications\/\" \/>\n<meta property=\"og:site_name\" content=\"Supportex.NET blog\" \/>\n<meta property=\"article:published_time\" content=\"2012-01-19T23:09:41+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-05-10T15:24:21+00:00\" \/>\n<meta name=\"author\" content=\"Oleksii Tykhonov\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Oleksii Tykhonov\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/supportex.net\/blog\/2012\/01\/nginx-fcgiwrap-deployment-cgi-applications\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/supportex.net\/blog\/2012\/01\/nginx-fcgiwrap-deployment-cgi-applications\/\"},\"author\":{\"name\":\"Oleksii Tykhonov\",\"@id\":\"https:\/\/supportex.net\/blog\/en\/#\/schema\/person\/0690c26a0266603129fc15eae6243251\"},\"headline\":\"nginx: Using fcgiwrap for CGI applications deployment\",\"datePublished\":\"2012-01-19T23:09:41+00:00\",\"dateModified\":\"2019-05-10T15:24:21+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/supportex.net\/blog\/2012\/01\/nginx-fcgiwrap-deployment-cgi-applications\/\"},\"wordCount\":230,\"keywords\":[\"linux\",\"niginx\"],\"articleSection\":[\"linux\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/supportex.net\/blog\/2012\/01\/nginx-fcgiwrap-deployment-cgi-applications\/\",\"url\":\"https:\/\/supportex.net\/blog\/2012\/01\/nginx-fcgiwrap-deployment-cgi-applications\/\",\"name\":\"nginx: Using fcgiwrap for CGI applications deployment &#8211; Supportex.NET blog\",\"isPartOf\":{\"@id\":\"https:\/\/supportex.net\/blog\/en\/#website\"},\"datePublished\":\"2012-01-19T23:09:41+00:00\",\"dateModified\":\"2019-05-10T15:24:21+00:00\",\"author\":{\"@id\":\"https:\/\/supportex.net\/blog\/en\/#\/schema\/person\/0690c26a0266603129fc15eae6243251\"},\"description\":\"How to use fcgiwrap for CGI applications deployment in nginx. Nginx fcgiwrap for CGI applications\",\"breadcrumb\":{\"@id\":\"https:\/\/supportex.net\/blog\/2012\/01\/nginx-fcgiwrap-deployment-cgi-applications\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/supportex.net\/blog\/2012\/01\/nginx-fcgiwrap-deployment-cgi-applications\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/supportex.net\/blog\/2012\/01\/nginx-fcgiwrap-deployment-cgi-applications\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/supportex.net\/blog\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"nginx: Using fcgiwrap for CGI applications deployment\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/supportex.net\/blog\/en\/#website\",\"url\":\"https:\/\/supportex.net\/blog\/en\/\",\"name\":\"Supportex.NET blog\",\"description\":\"Server and network management company\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/supportex.net\/blog\/en\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/supportex.net\/blog\/en\/#\/schema\/person\/0690c26a0266603129fc15eae6243251\",\"name\":\"Oleksii Tykhonov\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/supportex.net\/blog\/en\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/4fd5f58002717075c88963469b9babef?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/4fd5f58002717075c88963469b9babef?s=96&d=mm&r=g\",\"caption\":\"Oleksii Tykhonov\"},\"url\":\"https:\/\/supportex.net\/blog\/author\/oleksiitykhonov\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"nginx: Using fcgiwrap for CGI applications deployment &#8211; Supportex.NET blog","description":"How to use fcgiwrap for CGI applications deployment in nginx. Nginx fcgiwrap for CGI applications","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/supportex.net\/blog\/2012\/01\/nginx-fcgiwrap-deployment-cgi-applications\/","og_locale":"en_US","og_type":"article","og_title":"nginx: Using fcgiwrap for CGI applications deployment &#8211; Supportex.NET blog","og_description":"How to use fcgiwrap for CGI applications deployment in nginx. Nginx fcgiwrap for CGI applications","og_url":"https:\/\/supportex.net\/blog\/2012\/01\/nginx-fcgiwrap-deployment-cgi-applications\/","og_site_name":"Supportex.NET blog","article_published_time":"2012-01-19T23:09:41+00:00","article_modified_time":"2019-05-10T15:24:21+00:00","author":"Oleksii Tykhonov","twitter_misc":{"Written by":"Oleksii Tykhonov","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/supportex.net\/blog\/2012\/01\/nginx-fcgiwrap-deployment-cgi-applications\/#article","isPartOf":{"@id":"https:\/\/supportex.net\/blog\/2012\/01\/nginx-fcgiwrap-deployment-cgi-applications\/"},"author":{"name":"Oleksii Tykhonov","@id":"https:\/\/supportex.net\/blog\/en\/#\/schema\/person\/0690c26a0266603129fc15eae6243251"},"headline":"nginx: Using fcgiwrap for CGI applications deployment","datePublished":"2012-01-19T23:09:41+00:00","dateModified":"2019-05-10T15:24:21+00:00","mainEntityOfPage":{"@id":"https:\/\/supportex.net\/blog\/2012\/01\/nginx-fcgiwrap-deployment-cgi-applications\/"},"wordCount":230,"keywords":["linux","niginx"],"articleSection":["linux"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/supportex.net\/blog\/2012\/01\/nginx-fcgiwrap-deployment-cgi-applications\/","url":"https:\/\/supportex.net\/blog\/2012\/01\/nginx-fcgiwrap-deployment-cgi-applications\/","name":"nginx: Using fcgiwrap for CGI applications deployment &#8211; Supportex.NET blog","isPartOf":{"@id":"https:\/\/supportex.net\/blog\/en\/#website"},"datePublished":"2012-01-19T23:09:41+00:00","dateModified":"2019-05-10T15:24:21+00:00","author":{"@id":"https:\/\/supportex.net\/blog\/en\/#\/schema\/person\/0690c26a0266603129fc15eae6243251"},"description":"How to use fcgiwrap for CGI applications deployment in nginx. Nginx fcgiwrap for CGI applications","breadcrumb":{"@id":"https:\/\/supportex.net\/blog\/2012\/01\/nginx-fcgiwrap-deployment-cgi-applications\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/supportex.net\/blog\/2012\/01\/nginx-fcgiwrap-deployment-cgi-applications\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/supportex.net\/blog\/2012\/01\/nginx-fcgiwrap-deployment-cgi-applications\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/supportex.net\/blog\/en\/"},{"@type":"ListItem","position":2,"name":"nginx: Using fcgiwrap for CGI applications deployment"}]},{"@type":"WebSite","@id":"https:\/\/supportex.net\/blog\/en\/#website","url":"https:\/\/supportex.net\/blog\/en\/","name":"Supportex.NET blog","description":"Server and network management company","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/supportex.net\/blog\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/supportex.net\/blog\/en\/#\/schema\/person\/0690c26a0266603129fc15eae6243251","name":"Oleksii Tykhonov","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/supportex.net\/blog\/en\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/4fd5f58002717075c88963469b9babef?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4fd5f58002717075c88963469b9babef?s=96&d=mm&r=g","caption":"Oleksii Tykhonov"},"url":"https:\/\/supportex.net\/blog\/author\/oleksiitykhonov\/"}]}},"_links":{"self":[{"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/posts\/2519","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/comments?post=2519"}],"version-history":[{"count":4,"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/posts\/2519\/revisions"}],"predecessor-version":[{"id":3162,"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/posts\/2519\/revisions\/3162"}],"wp:attachment":[{"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/media?parent=2519"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/categories?post=2519"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/tags?post=2519"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}