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";
        }
}
yuyunc1 回答:Nginx多个位置的Laravel项目

您需要向/project2添加一些内容,以告诉nginx如何处理php文件。知道如何处理

的块

我从here抓取了以下内容。我已经更新了您的位置正则表达式,尽管我尚未进行测试,所以您可能需要对其进行修复(关于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网址以project2结尾,因此您需要做一点正则表达式魔术来提取正确的网址。

当然,如果可以使用目录结构使事情更简单,则可以使用更简单的正则表达式。

本文链接:https://www.f2er.com/3127902.html

大家都在问