最近,我们已从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
。现在要从同一域访问多个应用程序,我已将root指令更改为/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服务框架。
答案 0 :(得分:0)
通过更改以下代码块对我有用
从root /var/www/html/project1/public;
到root /var/www/html;
并且我们需要根据需求添加多个location
块。考虑到我想从单个域访问两个Lumen/ Laravel
应用程序,那么我需要添加两个location
块作为
location /project1/public {
try_files $uri $uri/ /project1/public/index.php$is_args$args;
}
location /project2/public {
try_files $uri $uri/ /project2/public/index.php$is_args$args;
}
贷方转到Richard Smith