So I am running a site www.example.com. Initially, I was using apache and any hit to my site would be redirected to www.example.com/path. Now this redirection is defined in my httpd.conf like:
Redirect 301 /index.html http://www.example.com/path
and my VirtualHost setting for this domain looks like this:
<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>
So basically when someone visits www.example.com, he is redirected to www.example.com/path which is executes a CGI script as defined by the ScriptAlias directive.
Everything was working fine until I had to do the following:
Install nginx and configured it to act as a reverse proxy for apache.
Now nginx listens to port 80 and apache listens to 8080. I made the changes in httpd.conf file accordingly.
Listen 8080
and
<VirtualHost 1.1.1.1:8080>
Now when someone tries to go to www.example.com, he is redirected to www.example.com/path but the script does not seem to execute. I am getting the following error on my web page:
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
The fact that it is redirecting tells me that the request from nginx to apache is working fine. There must be something wrong CGI execution. В журналах ошибок apache и nginx ничего нет.
Я этого не понимаю. С apache все работало нормально, но теперь, когда запрос достигает apache, что-то ломается.
Я исправил проблему, но я не понимаю, как она исправилась. В моём nginx conf, где я пересылаю запрос от nginx на порт 80 на apache на порту 8080, я заменил строку
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.
.