Nginx

CGI 停止將 Nginx 設置為 apache 的反向代理

  • March 11, 2017

所以我正在執行一個網站 www.example.com。最初,我使用的是 apache,任何對我網站的訪問都會被重定向到 www.example.com/path。現在這個重定向是在我的 httpd.conf 中定義的,比如:

Redirect 301 /index.html http://www.example.com/path

我的這個域的 VirtualHost 設置如下所示:

<VirtualHost 1.1.1.1:80>
   DirectoryIndex  index.php index.html index.htm index.shtml
   ServerAdmin root@www.example.com
   DocumentRoot "/var/www/html"
   ServerName www.example.com

   ScriptAlias /path "/path/to/cgi/script"

</VirtualHost>

所以基本上當有人訪問 www.example.com 時,他會被重定向到 www.example.com/path,它執行 ScriptAlias 指令定義的 CGI 腳本。

一切正常,直到我不得不執行以下操作:

安裝 nginx 並將其配置為 apache 的反向代理。

現在 nginx 監聽 80 埠,apache 監聽 8080。我在 httpd.conf 文件中進行了相應的更改。

Listen 8080

<VirtualHost 1.1.1.1:8080>

現在,當有人嘗試訪問 www.example.com 時,他會被重定向到 www.example.com/path,但腳本似乎沒有執行。我的網頁上出現以下錯誤:

Not Found

The requested URL /path was not found on this server.
Apache/2.4.25 (Unix) PHP/7.0.16 SVN/1.7.14 Server at www.example.com Port 80

它正在重定向的事實告訴我從 nginx 到 apache 的請求工作正常。CGI 執行一定有問題。apache 錯誤日誌和 nginx 錯誤日誌中沒有任何內容。

我不明白這個。apache 一切正常,但現在當請求到達 apache 時,出現了問題。

我解決了這個問題,但我不明白它是如何解決的。在我的 nginx conf 中,我將請求從埠 80 的 nginx 轉發到埠 8080 的 apache,我替換了該行

proxy_pass http://127.0.0.1:8080;

proxy_pass http://www.example.com:8080;

根據我的說法,127.0.0.1 和 www.example.com 應該與我的 nginx 安裝在 www.example.com 伺服器上相同。

引用自:https://serverfault.com/questions/837616