gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 14:15:49 24 4
gpt4 key购买 nike

我正在尝试配置 nginx 以在同一域上为 laravel 和 yii 项目提供服务。我的 Laravel 项目运行良好。 Yii 项目也正常运行,但 Assets yii 项目上的文件夹正在提供 错误中止 未找到 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;
}
}

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

最佳答案

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

关于nginx - 如何为laravel和yii项目正确配置nginx?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60076795/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com