Laravel 子目录的 NGINX 配置正确服务 PHP 和静态文件

问题描述 投票:0回答:1

我有 2 个 Laravel 站点;

我的主网站和我的婚礼网站 我在同一台服务器上部署了我的婚礼网站。我的婚礼网站与我的主网站位于不同的存储库中。下面是我的 nginx 配置

server {
    listen 443 ssl;
    server_name www.bunlongheng.com;

    ssl_certificate /etc/nginx/ssl/bunlongheng.com.crt;
    ssl_certificate_key /etc/nginx/ssl/bunlongheng.com.key;

    root /home/bheng/wedding/public;
    index index.html index.php;
    charset utf-8;
    client_max_body_size 500M;

    location ^~ /wedding {
        index index.html index.php;
        alias /home/bheng/wedding/public;
        add_header 'Access-Control-Allow-Origin' '*';
        try_files $uri $uri/ @wedding;

        location ~ \.php$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/var/run/php/php8.0-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include /etc/nginx/fastcgi_params;
        }
    }

    location @wedding {
        rewrite ^/wedding/(.*)$ /wedding/index.php?$1 last;
    }
}

我的婚礼似乎在从我的婚礼存储库加载资产时遇到问题:

https://www.bunlongheng.com/wedding/

enter image description here

我的婚礼项目在我的本地完美加载

enter image description here

有人可以帮助我进行正确的配置,以使我的婚礼网站正确加载资源吗?

css laravel nginx
1个回答
0
投票

确保

try_files
指令在传递给 @wedding 之前包含对静态文件的所有必要检查。例如:

try_files $uri $uri/ /wedding/index.php?$args;

然后重新启动

sudo systemctl restart nginx

© www.soinside.com 2019 - 2024. All rights reserved.