微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

if-statement-使用Puppet Nginx jfryman模块将if else置于nginx Vhost配置中

我想为一个具有一些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遇到了同样的问题.

In 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; }',},}

原文地址:https://www.jb51.cc/nginx/532246.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐