如何配置nginx来服务laravel创建的动态创建目录并正确加载HTML和CSS?

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

如何配置nginx以服务laravel创建的动态创建目录并正确加载HTML和CSS?

对于运行vesta控制面板的ubuntu 18.04下的laravel动态创建的子目录,nginx已成功在网站根目录加载HTML内容,但未成功加载CSS内容。例如,使用以下nginx conf一个由Orchid管理面板动态创建的子目录,位于:somesite.com/dashboard在网站根目录加载HTML内容,但不在CSS内容中加载。

任何帮助将不胜感激。

/ home / user / conf / web / somesite.com.nginx.conf:

server {
    listen      some-server-ip:80;
    server_name somesite.com www.somesite.com;
    root        /home/user/web/somesite.com/chat/public;
    index       index.php index.html index.htm;
    access_log  /var/log/nginx/domains/somesite.com.log combined;
    access_log  /var/log/nginx/domains/somesite.com.bytes bytes;
    error_log   /var/log/nginx/domains/somesite.com.error.log error;




    location / {

    try_files $uri $uri/ /index.php?$query_string;  

        location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|css|js)$ {
            expires     max;
        }

        location ~ [^/]\.php(/|$) {
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            if (!-f $document_root$fastcgi_script_name) {
                return  404;
            }

            fastcgi_pass    127.0.0.1:9002;
            fastcgi_index   index.php;
            include         /etc/nginx/fastcgi_params;
        }
    }

    error_page  403 /error/404.html;
    error_page  404 /error/404.html;
    error_page  500 502 503 504 /error/50x.html;

    location /error/ {
        alias   /home/user/web/somesite.com/document_errors/;
    }

    location ~* "/\.(htaccess|htpasswd)$" {
        deny    all;
        return  404;
    }

    location /vstats/ {
        alias   /home/user/web/somesite.com/stats/;
        include /home/user/conf/web/somesite.com.auth*;
    }

    include     /etc/nginx/conf.d/phpmyadmin.inc*;
    include     /etc/nginx/conf.d/phppgadmin.inc*;
    include     /etc/nginx/conf.d/webmail.inc*;

    include     /home/user/conf/web/nginx.somesite.com.conf*;
}
laravel nginx dynamic subdirectory vesta
1个回答
0
投票

兰花完全依赖Laravel设置

server {
listen 80;
server_name example.com;
root /example.com/public;

add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";

index index.html index.htm index.php;

charset utf-8;

location / {
    try_files $uri $uri/ /index.php?$query_string;
}

location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt  { access_log off; log_not_found off; }

error_page 404 /index.php;

location ~ \.php$ {
    fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
    include fastcgi_params;
}

location ~ /\.(?!well-known).* {
    deny all;
}

}

请注意documentation

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