Nginx + php5-fpm = 404别名位置错误

时间:2016-06-02 03:26:50

标签: php ubuntu nginx

我是业余前端Web开发人员,我最近购买了一台Ubuntu服务器试图在后端开发中尝试。我试图弄清楚如何使用php5-fpm从别名位置块提供php文件。我收到404 - 找不到页面错误。我已经尝试了所有我在这里找到的解决方案,没有运气。因为我还是初学者,我也会喜欢快速的ELI5以及我的conf文件的其余部分,所以我也可以学到一些东西。我应该提到主根文件夹正在运行一个烧瓶应用程序,这就是我使用别名位置的原因。

我的虚拟主机:

Nginx配置文件

server {
listen 80;
listen [::]:80;
server_name www.example.com example.com;

root /var/www/example;
large_client_header_buffers 8 32k;
access_log /var/www/example/logs/access.log;
error_log /var/www/example/logs/error.log;


location / {
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $remote_addr; #$proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_set_header X-NginX-Proxy true;
    proxy_pass http://app_test;
    proxy_redirect off;
}


 location /test_site {
     alias /var/www/test_site;
     index index.php index.html index.htm;
     location ~ .php$ {
                try_files $uri =404;
                fastcgi_split_path_info ^(.+?\.php)(/.*)?$;
                fastcgi_pass unix:127.0.0.1:9000;
                fastcgi_index index.php;
                include fastcgi_params;
     }
  }

php5 www.conf文件

[www]
...
user = www-data
group = www-data


listen = 127.0.0.1:9000
#listen = /tmp/php5-fpm.sock

listen.owner = www-data
listen.group = www-data
listen.mode = 0660
...

我的fastcgi_params文件是默认的。我检查了php和nginx日志,没有错误。任何帮助将非常感激!

1 个答案:

答案 0 :(得分:0)

使用aliasfastcgi使用嵌套位置非常复杂。

假设您没有简化配置,test_site位置无需使用alias

location /test_site {
    root /var/www;
    index index.php index.html index.htm;
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:127.0.0.1:9000;
        include fastcgi_params;
    }
}

这将删除alias指令,并解决PHP块中的别名问题。

另请注意:location ~ \.php$块上的正则表达式错误。 <{1}}和fastcgi_split_path_info指令是不必要的。

fastcgi_index指令为documented here