Nginx多个地点laravel项目



我在为Nginx安装程序设置第二组位置时遇到问题。我目前有1个工作路由,使用反向代理到NodeJS Express服务器。

我正在尝试设置第二个位置来服务于一个laravel项目,这是我的Nginx配置文件,我知道有一些错误,但在谷歌上搜索后,我自己找不到答案。

感谢

server {
listen 443 http2 ssl;
listen [::]:443 http2 ssl;
server_name some.server.com
ssl on;
ssl_certificate /etc/letsencrypt/live/some.server.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/some.server.com/privkey.pem;
# This doesnt work, its a laravel project
# Theres something wrong with my try_files
location /project2 {
root /home/ubuntu/project2/public/;
try_files $uri $uri/ /index.php?$query_string;
}
# This works, I am reverse proxying to NodeJS Application
location / {
proxy_pass http://localhost:3001;
proxy_set_header Host $http_host;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}

您需要在/project2中添加一些东西,告诉nginx如何处理php文件。一个知道如何处理的区块

我从这里抓了下面的。我更新了你的位置regex,虽然我还没有测试,所以你可能需要修复它(关于nginx的一切都是反复尝试的,直到它工作为止(:

location ~* /project2/(.*.php)$ {
root /home/ubuntu/project2/public/;
try_files $1 $1/ $1/index.php?$query_string;
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

您从/home/ubuntu/project2/public/提供服务,但您的php url以project2结尾,因此您需要执行一些regex魔术来提取正确的url。

当然,如果您可以通过目录结构使事情变得更简单,那么您可以使用更简单的regex。

最新更新