【发布时间】:2019-08-05 08:37:55
【问题描述】:
最近我们从Apache2 迁移到Nginx 服务器。考虑我们有域www.test.com,下面是www.test.com.conf,我禁用了default Nginx 默认文件。
server {
server_name www.test.com;
# Character Set
charset utf-8;
# Logs
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
# Directory Indexes
index index.html index.htm index.php;
# Document Root
root /var/www/html/project1/public;
# Location
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
# Error Pages
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
# PHP-FPM Support
location ~ \.php$ {
fastcgi_read_timeout 240;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock; #/var/run/php5-fpm.sock;
#include fastcgi.conf;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# Block access to .htaccess
location ~ \.htaccess {
deny all;
}
client_body_timeout 10s;
client_header_timeout 10s;
client_max_body_size 100M;
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/www.test.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/www.test.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = www.test.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen *:80;
server_name www.test.com;
return 404; # managed by Certbot
}
通过上述配置,我可以毫无问题地访问https://www.test.com。在这种情况下,根 /var/www/html/project1/public。现在要从同一个域访问多个应用程序,我已将根指令更改为 /var/www/html/ 并尝试访问 https://www.test.com/project1/public 但我收到以下错误
FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream
我可以知道这个问题的原因吗?我的应用程序是Lumen,它是Laravel 的一个mirco 服务框架。
【问题讨论】:
-
您的
try_files语句指定了/index.php,它可能应该更改为您想要的默认项目(例如/project1/public/index.php)。 -
@RichardSmith 它对我有用,如果我有多个项目,如
project1、project2并请求基于https://www.test.com/project1/public和https://www.test.com/project2/等 URL 的相关项目? -
对每个项目使用单独的
location块,并使用包含适当默认 URI 的try_files语句。
标签: nginx webserver lumen nginx-config