@H_301_1@我想为一个具有一些if条件语句的网站自动执行Nginx vhost配置.我试图使用jfryman-nginx人偶伪造模块来执行此操作,但无法配置该文件.我想要的配置如下:
@H_301_1@
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;
}
@H_301_1@因此,如果条件在我的vhost配置中,我该如何放置它:
@H_301_1@
if (!-f $request_filename){
set $rule_4 1$rule_4;
}
@H_301_1@可以吗?我已经尝试过location_cfg_prepend,但这没有帮助.最佳答案
我对jfryman-Nginx v0.0.9遇到了同样的问题.
@H_301_1@In the latest source templates on github,看起来像;如果您使用location_custom_cfg_ {pre,ap} pend,则不应添加.
@H_301_1@但是in v0.0.9,the latest bundled puppet forge release,模板添加了;即使该行仅包含},也会导致Nginx失败.
@H_301_1@解决方案:
@H_301_1@>使用location _ ** custom ** _ cfg_ {pre,ap}挂起选项
> A或B: @H_301_1@A.编辑出;在模板中 @H_301_1@B.从github拉取最新版本的源代码: @H_301_1@须藤rm -rf / etc / puppet / modules / Nginx&& cd / etc / puppet / modules&&须藤git clone https://github.com/jfryman/puppet-nginx Nginx @H_301_1@例 @H_301_1@
原文链接:https://www.f2er.com/nginx/532246.html> A或B: @H_301_1@A.编辑出;在模板中 @H_301_1@B.从github拉取最新版本的源代码: @H_301_1@须藤rm -rf / etc / puppet / modules / Nginx&& cd / etc / puppet / modules&&须藤git clone https://github.com/jfryman/puppet-nginx Nginx @H_301_1@例 @H_301_1@
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; }',},}