【问题标题】:nginx and apache - Error processing php filesnginx 和 apache - 处理 php 文件时出错
【发布时间】:2012-07-18 11:15:44
【问题描述】:

我还在学习nginx,如果答案很明显,请多多包涵:)。

我已经使用these instructions在apache前面设置了nginx

nginx 似乎正在正确处理 html 文件,但是每当我尝试访问 php 文件时,我都会收到 404 错误。

这里是 nginx example.com 配置文件

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 个小时的大部分时间里,我一直在试图找出我的错误在哪里。我希望你能提供帮助:(

【问题讨论】:

    标签: php nginx apache2


    【解决方案1】:

    proxy_pass http://127.0.0.1:8080;&lt;VirtualHost 123.45.67.89:8080&gt; 看起来不一样。

    而且 nginx 配置看起来不对。如果您阅读the official documentation,也许您的运气会更好。

    【讨论】:

    • 你是对的,我将 VirtualHost 更改为 并且它工作...
    • 如果你想只收听本地接口,你应该改为127.0.0.1:8080,这样会更安全。
    猜你喜欢
    • 2016-09-08
    • 1970-01-01
    • 2019-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-16
    • 2018-10-03
    相关资源
    最近更新 更多