我想为一个具有一些if条件语句的网站自动执行Nginx vhost配置.我试图使用jfryman-nginx人偶伪造模块来执行此操作,但无法配置该文件.我想要的配置如下:
server {
listen 8080;
server_name abcqwe.com;
root /data/vvv/abcqwe.com;
index index.PHP index.html index.htm;
access_log /data/vvv/abcqwe.com/logs/access.log;
error_log /data/vvv/abcqwe.com/logs/error.log;
location / {
# First attempt to serve request as file,then
# as directory,then fall back to index.html
#try_files $uri $uri/ /index.html;
if (!-f $request_filename){
set $rule_0 1$rule_0;
}
try_files $uri $uri/ /index.html;
}
因此,如果条件在我的vhost配置中,我该如何放置它:
if (!-f $request_filename){
set $rule_4 1$rule_4;
}
可以吗?我已经尝试过location_cfg_prepend,但这没有帮助.
最佳答案
我对jfryman-Nginx v0.0.9遇到了同样的问题.
原文链接:https://www.f2er.com/nginx/532246.htmlIn the latest source templates on github,看起来像;如果您使用location_custom_cfg_ {pre,ap} pend,则不应添加.
但是in v0.0.9,the latest bundled puppet forge release,模板添加了;即使该行仅包含},也会导致Nginx失败.
解决方案:
>使用location _ ** custom ** _ cfg_ {pre,ap}挂起选项
> A或B:
A.编辑出;在模板中
B.从github拉取最新版本的源代码:
须藤rm -rf / etc / puppet / modules / Nginx&& cd / etc / puppet / modules&&须藤git clone https://github.com/jfryman/puppet-nginx Nginx
例
Nginx::resource::location { 'sub.dom.com_root':
ensure => present,vhost => 'sub.dom.com',location => '~ \.PHP$',fastcgi => 'unix:/var/run/PHP5-fpm.sock',www_root => '/var/www/sub.dom.com',location_custom_cfg_append => {
'if (-f $request_filename)' => '{ break; }','if (-d $request_filename)' => '{ break; }','if ($request_filename !~ (js|css|jpg|png|gif|robots\.txt|index\.PHP.*) )' => '{ rewrite ^/(.*) /index.PHP?$1 last; }',},}