- Nginx Web Server 以及 php 套件安裝,請參考這一篇!
-
安裝 EPEL 套件:
#yum install epel-release #yum upgrade epel-release
-
利用 YUM ,安裝 fcgiwrap 以及 spawn-fcgi:
#yum install fcgiwrap spawn-fcgi
-
設定系統參數,方便 spawn-fcgi 運用:
#vim /etc/sysconfig/spawn-fcgi FCGI_SOCKET=/var/run/fcgiwrap.socket FCGI_PROGRAM=/usr/sbin/fcgiwrap FCGI_USER=nginx FCGI_GROUP=nginx FCGI_EXTRA_OPTIONS="-M 0700" OPTIONS="-u $FCGI_USER -g $FCGI_GROUP -s $FCGI_SOCKET -S $FCGI_EXTRA_OPTIONS -F 1 -P /var/run/spawn-fcgi.pid -- $FCGI_PROGRAM"
-
啟動 spawn-fcgi 服務:
#systemctl enable spawn-fcgi #systemctl start spawn-fcgi
-
修改 Nginx 設定檔內容:
# server { (中間其他設定omit) location /monitorix/ { alias /var/lib/monitorix/www/; index index.html; } location /monitorix-cgi/ { gzip off; alias /var/lib/monitorix/www/cgi/; fastcgi_pass unix:/var/run/fcgiwrap.socket; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } (中間其他設定omit) }
-
重新啟動 nginx 服務:
#systemctl restart nginx
-
寫一測試檔案:
#vim /var/share/nginx/html/test.cgi #!/usr/bin/perl -w print "Content-type: text/html\n\n"; print "<html><head><title>Hello World!! </title></head>\n"; print "<body><h1>Hello world</h1> </body></html>\n";
-
設定權限:
#chmod 0755 /var/share/nginx/html/test.cgi #chown nginx.nginx /var/share/nginx/html/test.cgi
- 利用 firefox 測試!(http://localhost/test.cgi)
參考文獻:
- https://www.howtoforge.com/serving-cgi-scripts-with-nginx-on-centos-6.0-p2