我在我的实验室里把Apache改成了Nginx,我们在子域下有很多projets,所以我用一种方法,每个子目录的服务器都运行在一个高端口(8000或者更高),而主服务器在80代理他们。 我的80服务器是这样configuration的:
include /etc/nginx/sites-enabled/*.conf; upstream php { server unix:/run/php-fpm.sock; } server { server_name example.com; listen 80; location / { proxy_pass http://127.0.0.1:8000; } location /application { proxy_pass http://127.0.0.1:8001; } location /phpmyadmin { proxy_pass http://127.0.0.1:8002; } }
所以我有另外三个服务监听不同的端口,如下所示:
server { listen 8000; root /var/www/path/to/application; index index.php; location / { try_files $uri $uri/ /index.php?$args =404; } location ~ \.php$ { include fastcgi_params; fastcgi_pass php; } }
这第一个是一个WordPress的应用程序。 出于某种原因,它redirect到127.0.0.1,而不是代理传递,并在本地主机我没有任何运行,所以我得到404。但在另一个域。 像什么?
8001的服务尚不存在。 在8002的服务是phpmyadmin像这样运行:
server { listen 8002; root /var/www/path/to/phpmyadmin; index index.php; location / { try_files $uri $uri/ /index.php?$args =404; } location ~ \.php$ { include fastcgi_params; fastcgi_pass php; } }
这一个报告错误404,尽pipe文件存在,但至less不redirect到127.0.0.1。 Nginx报告没有错误,PHP-FPM也没有听到这个套接字。
什么是错误configuration,我怎样才能解决这些奇怪的不一致的错误?
您不需要使您的configuration变得复杂。 试试这个方法:
include /etc/nginx/sites-enabled/*.conf; upstream php { server unix:/run/php-fpm.sock; } server { server_name example.com; listen 80; location / { try_files $uri $uri/ /index.php?$args =404; } location /application { proxy_pass http://127.0.0.1:8001; } location /phpmyadmin { try_files $uri $uri/ /index.php?$args =404; } location ~ \.php$ { include fastcgi_params; fastcgi_pass php; } }