我已将我的站点拆分为不同的配置文件,以使事情更有条理。这也允许我删除单个配置文件并使站点不可用。
每个站点的配置文件如下所示:
server {
listen 80;
server_name site1.domain.co.uk;
root /var/www/php/site1;
location / {
index index.html index.php;
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
try_files $uri /index.php;
fastcgi_pass php;
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location /common {
alias /var/www/common;
}
}
我的问题是,我是否必须为每个站点重复 location 块?或者我可以添加一个匹配所有内容的新服务器块吗?如果这是可能的,它会与我匹配所有未映射到站点的域的配置文件冲突吗?该配置文件如下所示:
server {
listen 80 default_server;
server_name _;
return 404;
}
或者,我做错了吗?虽然不是这个问题的主要目的,但如果有人能告诉我配置中的任何重大错误,那就太好了。
谢谢。
如果你想为每个主机保留单独的配置文件,但每个主机之间的配置的某些部分相同,那么你可能想使用
include
.在
server
每个站点文件的块中:..并让该文件包含
location
块。