我需要設置nginx的配置,使得URL 「http://host/cgi-bin/hw.sh/some/path/to/data/」 應觸發shell腳本 「hw.sh」 當前路徑下的「/usr/lib目錄/ cgi-bin目錄/ 」。需要幫助的Nginx的CGI配置
現在,根據頁面https://www.howtoforge.com/serving-cgi-scripts-with-nginx-on-debian-squeeze-ubuntu-11.04-p3中提到的說明,我們需要在「.vhost」文件下設置配置。但我有一個默認文件已經存在路徑「/etc/nginx/sites-available/default」,而不是.vhost文件。
而當我使用相同的配置時,我得到HTTP/1.1 403 Forbidden錯誤。我確定腳本也需要可執行權限。以下是nginx日誌中收到的錯誤。
FastCGI sent in stderr: "Cannot get script name, are DOCUMENT_ROOT and SCRIPT_NAME (or SCRIPT_FILENAME) set and is the script executable?"
while reading response header from upstream,
client: host_ip, server: localhost,
request: "HEAD /cgi-bin/hw.sh/some/path/to/data/ HTTP/1.1",
upstream: "fastcgi://unix:/var/run/fcgiwrap.socket:", host: "host_ip"
我需要寫正確的配置,使我上面的網址執行上述路徑下的hw.sh腳本,並返回正確的輸出幫助。有人可以幫我在這裏嗎?
下面是我在默認文件下使用的配置。
server {
listen 80 default_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 /usr/lib;
# 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;
}
[...]
}
CGI與FastCGI完全不同,但[此頁可能對您有所幫助](https://www.nginx.com/resources/wiki/start/topics/examples/fcgiwrap/)。 –