加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 运营中心 > Nginx > 正文

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

发布时间:2020-12-13 20:53:38 所属栏目:Nginx 来源:网络整理
导读:我想为一个具有一些if条件语句的网站自动执行nginx vhost配置.我试图使用jfryman-nginx人偶伪造模块来执行此操作,但无法配置该文件.我想要的配置如下: server { listen 8080; server_name abcqwe.com; root /data/vvv/abcqwe.com; index index.php index.ht

我想为一个具有一些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; }',},}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读