我想有两个proxy_pass位置和一个通用的php-fpm位置以及任何.php请求被转发到fpm-php,但任何请求/ el / …或/ gl / …去那些位置。 这是我迄今为止:
server { listen *:443 ssl; ssl_certificate /etc/nginx/ssl/nginx.crt; ssl_certificate_key /etc/nginx/ssl/nginx.key; client_max_body_size 108M; access_log /var/log/nginx/access.log; root /var/www/public; index index.php; if (!-e $request_filename) { rewrite ^.*$ /index.php last; } location /es/ { proxy_pass http://<my-domain>:8200/; } location /gl/ { proxy_pass http://<my-domain>:3000/; } location / { location ~ \.php$ { fastcgi_pass <my-domain>:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PHP_VALUE "error_log=/var/log/nginx/php_errors.log"; fastcgi_buffers 16 16k; fastcgi_buffer_size 32k; include fastcgi_params; } } }
这个configuration在三个方面都失败了。 然而,删除所有的PHP位置和“if”声明适用于/ es /和/ gl / locations,所以我想我没有正确地执行php位。 达到这个目标的最好方法是什么? 谢谢。
你应该重写:
if (!-e $request_filename) { rewrite ^.*$ /index.php last; }
如:
try_files $uri $uri/ /index.php;
并将其移入location /块,以避免与全局if和rewrite语句的讨厌冲突。
在优先于正则expression式位置的前缀位置上使用^~修饰符。 详情请参阅此文件 。
例如:
root /var/www/public; index index.php; location ^~ /es/ { proxy_pass http://<my-domain>:8200/; } location ^~ /gl/ { proxy_pass http://<my-domain>:3000/; } location / { try_files $uri $uri/ /index.php; } location ~ \.php$ { try_files $uri =404; fastcgi_pass <my-domain>:9000; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PHP_VALUE "error_log=/var/log/nginx/php_errors.log"; fastcgi_buffers 16 16k; fastcgi_buffer_size 32k; }
将fastcgi_param语句放在include fastcgi_params; 避免被包含文件默默覆盖。