繁体   English   中英

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

[英]Nginx + php5-fpm = 404 Error with alias location

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

我的虚拟主机:

Nginx conf文件

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日志,没有错误。 任何帮助将非常感激!

使用fastcgi获取alias以使用嵌套位置非常复杂。

假设您没有简化配置, 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$ block的正则表达式是错误的。 fastcgi_split_path_infofastcgi_index指令是不必要的。

这里记录了 nginx指令。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM