Я пытался обслуживать CGI-скрипты с помощью Nginx с помощью fcgiwrap, вот мои шаги:
- apt-get install fcgiwrap
sudo vi / etc / nginx / sites-enabled/www.example.com.conf и добавьте раздел скрипта на сервер {} следующим образом:
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
- mkdir / var/www/www.example.com/cgi-bin
- sudo vi /var/www/www.example.com/cgi-bin/hello_world.cgi
- sudo chmod 755 / var /www / www.example.com / cgi-bin / hello_world.cgi
- open http://www.example.com/cgi-bin/hello_world.cgi
Но когда я открываю http://www.example.com/cgi-bin/hello_world.cgi, я получаю 502 плохих шлюза иэтот журнал ошибок:
2018/12/12 10:18:38 [error] 10438#10438: *645 upstream prematurely closed FastCGI stdout while reading response header from upstream, client: xxx.xxx.xxx.xxx, server: http://www.example.com, request: "GET /cgi-bin/hello.cgi HTTP/2.0", upstream: "fastcgi://unix:/var/run/fcgiwrap.socket:", host: "http://www.example.com"
примечания: но когда я изменяю /var/run/fcgiwrap.socket
на /etc/init.d/fcgiwrap
, я получаю другой журнал ошибок:
2018/12/12 11:06:52 [error] 15393#15393: *1 connect() to unix:/etc/init.d/fcgiwrap failed (111: Connection refused) while connecting to upstream, client: xxx.xxx.xxx.xxx, server: http://www.example.com, request: "GET /cgi-bin/hello.cgi HTTP/2.0", upstream: "fastcgi://unix:/etc/init.d/fcgiwrap:", host: "http://www.example.com"
Итак, как я могу исправить эту ошибку ???