如何为laravel和yii项目正确配置nginx?

mer*_*dan 6 nginx yii

我正在尝试配置 nginx 以在同一域上为 laravel 和 yii 项目提供服务。我的 Laravel 项目运行良好。Yii 项目也可以工作,但 yii 项目上的资产文件夹给出err_aborted not found 404。所有 js css ... 文件未找到

server {

server_name mydomain.com;
index index.html index.php;
charset utf-8;
set $base_root /var/www;
# App 1 (main app)
location / {
    root $base_root/telemele/public;
    try_files $uri $uri/ /index.php?$query_string;
    error_log /var/log/nginx/telemele.notice.log notice;
    error_log /var/log/nginx/telemele.error.log error;

    location ~* ^/index\.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/run/php/php7.2-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME /var/www/telemele/public/index.php;
        fastcgi_intercept_errors off;
        fastcgi_buffer_size 16k;
        fastcgi_buffers 4 16k;
    }
}

# App 2
location ~* /mahabat {
    alias $base_root/html/backend/web;
    try_files $uri $uri/ /mahabat/index.php?$query_string;

    error_log /var/log/nginx/mahabat.notice.log notice;
    error_log /var/log/nginx/mahabat.error.log error;

    location ~* ^/mahabat/index\.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/run/php/php7.2-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME /var/www/html/backend/web/index.php;
        fastcgi_intercept_errors off;
        fastcgi_buffer_size 16k;
        fastcgi_buffers 4 16k;
    }
location ~* \.css|\.js|\.jpg|\.jpeg|\.png|\.gif|\.swf|\.svg|\.tiff|\.pdf$ {
 try_files $uri =404;
 }

location ~ ^/assets/.+\.php(/|$) {
        deny all;
    }
}

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

# Error
access_log off;
rewrite_log on;

# Disable .htaccess access
location ~ /\.ht {
    deny all;
}
}
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?如何让 nginx 不中止资产文件夹文件?为什么它没有找到?

小智 6

frontend/web 目录中可能缺少 .htacces 文件。如果你有同样的问题,我建议你使用这个