这是我的主要内容.conf
:
server {
# Default configuration
server_name dev.mysite.com;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
index index.php index.html;
charset utf-8;
root /opt/www;
# Logging
access_log /var/log/nginx/access.log main;
error_log /var/log/nginx/error.log debug;
location /manager {
error_log /var/log/nginx/manager_error.log ;
access_log /var/log/nginx/manager_access.log ;
alias /opt/www/manager;
try_files $uri $uri/ @laravel ;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass unix:/var/run/php-fpm/www.sock;
}
}
location ~/site/ {
deny all;
return 404;
}
}
server {
server_name stage.mysite.com
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
index index.php index.html;
access_log /var/log/nginx/access.site.log main;
error_log /var/log/nginx/error.site.log;
root /opt/www/site;
location / {
try_files $uri $uri/ =404;
}
location ~*\.php {
include snippets/fastcgi-php.conf;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass unix:/var/run/php-fpm/www.sock;
}
}
基本上,我有两个网站,一个在 下/opt/www/manager
,一个在 下/opt/www/site
。当我访问时,dev.mysite.com/manager
我可以看到应用程序正在运行。但是当我访问时,dev.mysite.com/site
我得到的是 的下载/opt/www/site/index.php
。为什么?
答案1
解决方案是在任何位置之前放置一个默认的 try 文件指令:
try_files $uri =404;