我有两个应用程序。一个是简单的php文件,另一个是zend框架应用程序。我正在使用Nginx。它适用于简单的php应用程序,可通过example.com/访问。
对于ZF3应用程序,nginx仅适用于父路由,并且没有子路由正在运行。父路线可通过example.com/products访问。我希望nginx能够处理路由操作,例如example.com/products/add,example.com/products/view,它们已在模块配置中定义。
nginx config
server {
listen *:80;
server_name example.com;
index index.html index.htm index.php;
access_log /var/log/nginx/simpleapp.access.log combined;
error_log /var/log/nginx/simpleapp.error.log;
root /var/www/simpleapp;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ^~ /products {
alias /var/www/ecom/public;
try_files $uri $uri/ /index.php$is_args$args;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
}
}
}
nginx日志文件
FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream
什么有效:
什么不起作用:
答案 0 :(得分:1)
对于相同的php处理,你真的需要两个不同的声明吗?我会坚持使用一个,只使用/product
上的别名区分根,例如:
server {
listen *:80;
server_name example.com;
index index.html index.htm index.php;
access_log /var/log/nginx/simpleapp.access.log combined;
error_log /var/log/nginx/simpleapp.error.log;
root /var/www/simpleapp;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location /products {
alias /var/www/ecom/public;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}