假设我为一个域设置了一个nginx配置,如下所示:
server {
root /path/to/one;
server_name one.example.org;
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
现在,如果我想添加另一个具有不同内容的域,有没有方法可以重用前一个域中的等价语句,或者我必须为我想要支持的每个新域复制所有内容?
server {
root /path/to/two; # different
server_name two.example.org; # different
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
我尝试将location
指令移到server
闭包之外,但很明显事情并不是这样的,因为在重启nginx时,我得到了一个错误"location directive is not allowed here“。
发布于 2013-03-30 03:16:22
您可以执行以下操作:
server_name one.example.org two.example.org;
如果两者除了域名之外完全相同
如果您只是有类似的位置块,您可以将这些位置移动到单独的文件中,然后执行
include /etc/nginx/your-filename;
为了在每个服务器块中轻松地使用它
https://stackoverflow.com/questions/15704919
复制相似问题