在ubuntu下為nginx配置支持cgi腳本的方案
在nginx下支持cgi腳本于支持node類似的,只要在nginx直接做個(gè)轉(zhuǎn)發(fā),轉(zhuǎn)發(fā)到對(duì)應(yīng)的cgi套接字就好。
使用Fcgiwrap
Fcgiqwrap是另外一個(gè)CGI封裝庫,跟Simple CGI類似。
安裝fcgiwrap
apt-get install fcgiwrap
安裝以后fcgiwrap默認(rèn)已經(jīng)啟動(dòng),對(duì)應(yīng)的套接字是 /var/run/fcgiwrap.socket 。如果沒有啟動(dòng),使用 /etc/init.d/fcgiwrap 手動(dòng)啟動(dòng)。
配置nginx的vhost文件
在要支持cgi腳本的路徑下,添加對(duì)應(yīng)的server配置。比如所有的cgi都在cgi-bin路徑下:
server {
[...]
location /cgi-bin/ {
# Disable gzip (it makes scripts feel slower since they have to complete
# before getting gzipped)
gzip off;
# Set the root to /usr/lib (inside this location this means that we are
# giving access to the files under /usr/lib/cgi-bin)
root /var/www/www.example.com;
# Fastcgi socket
fastcgi_pass unix:/var/run/fcgiwrap.socket;
# Fastcgi parameters, include the standard ones
include /etc/nginx/fastcgi_params;
# Adjust non standard parameters (SCRIPT_FILENAME)
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
[...]
}
重新加載nginx:
nginx -s reload
測試
在cgi-bin下創(chuàng)建hello-world.cgi
#!/usr/bin/perl -w # Tell perl to send a html header. # So your browser gets the output # rather then <stdout>(command line # on the server.) print "Content-type: text/html\n\n"; # print your basic html tags. # and the content of them. print "<html><head><title>Hello World!! </title></head>\n"; print "<body><h1>Hello world</h1></body></html>\n";
設(shè)置執(zhí)行權(quán)限
chmod 755 /var/www/www.example.com/cgi-bin/hello_world.cgi
在瀏覽器打開對(duì)應(yīng)腳本,即可看到已經(jīng)配置成功! http://www.example.com/cgi-bin/hello_world.cgi
- shell腳本定時(shí)統(tǒng)計(jì)Nginx下access.log的PV并發(fā)送給API保存到數(shù)據(jù)庫
- Apache Nginx 禁止目錄執(zhí)行PHP腳本文件的方法
- 詳解Nginx SSL快速雙向認(rèn)證配置(腳本)
- 使用shell腳本對(duì)Nginx日志進(jìn)行切分的示例代碼
- nginx源碼分析configure腳本詳解
- Nginx中使用Lua腳本配置示例
- PHP腳本監(jiān)控Nginx 502錯(cuò)誤并自動(dòng)重啟php-fpm
- Nginx和PHP-FPM的啟動(dòng)、重啟、停止腳本分享
- Linux下創(chuàng)建nginx腳本-start、stop、reload…
- shell腳本之nginx自動(dòng)化腳本
相關(guān)文章
解決Nginx無法啟動(dòng) -10013: An attempt was
這篇文章主要給大家介紹了解決用nginx -t 發(fā)成Nginx無法啟動(dòng)報(bào)錯(cuò)10013: An attempt was made to access a socket in a way forbidden by its access permissions的問題,需要的朋友可以參考下2023-11-11
使用Docker主機(jī)啟動(dòng)Nginx服務(wù)器的完整步驟詳解
Docker是一個(gè)開源的容器化平臺(tái),用于輕松地打包、部署和運(yùn)行應(yīng)用程序,而Nginx是一個(gè)高性能的開源反向代理服務(wù)器,也是一個(gè)流行的Web服務(wù)器,這篇文章主要給大家介紹了關(guān)于使用Docker主機(jī)啟動(dòng)Nginx服務(wù)器的完整步驟,需要的朋友可以參考下2024-07-07

