我还在学习nginx,所以如果答案很明显,请耐心等待。)。
在apache前面设置了nginxnginx似乎正在正确处理html文件,但是无论何时我尝试访问php文件,我都会收到404错误。
这是nginx example.com conf文件
server {
listen 80;
access_log /var/www/example.com/logs/nginx.access.log;
error_log /var/www/example.com/logs/nginx.error.log;
root /var/www/example.com/prod;
index index.php index.html index.htm;
server_name www.example.com example.com;
location \ {
try_files $uri $uri/ index.php/$uri;
}
location ~* ^.*\.php$ {
if (!-f $request_filename) {
return 404;
}
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:8080;
}
location ~ /\.(ht|git) {
deny all;
}
}
这是我的apache example.com conf文件
<VirtualHost 123.45.67.89:8080>
ServerName example.com
ServerAlias www.example.com
ServerAdmin webmaster@example.com
#Indexes + Directory Root
DirectoryIndex index.html index.htm index.php
DocumentRoot /var/www/example.com/prod/
#CGI Directory
ScriptAlias /cgi-bin/ /var/www/example.com/prod/cgi-bin/
<location /cgi-bin>
Options +ExecCGI
</location>
#Log Files
ErrorLog /var/www/example.com/logs/error.log
CustomLog /var/www/example.com/logs/access.log combined
</VirtualHost>
我一直试图弄清楚我的错误在4小时内的大部分时间。我希望你能帮忙:(
答案 0 :(得分:0)
proxy_pass http://127.0.0.1:8080;
和<VirtualHost 123.45.67.89:8080>
看起来不一样。
nginx配置看起来不对。如果你阅读the official documentation,也许你会有更好的运气。