Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple Location Problem #1221

Closed
pfflaren opened this issue Jun 20, 2018 · 3 comments
Closed

Multiple Location Problem #1221

pfflaren opened this issue Jun 20, 2018 · 3 comments

Comments

@pfflaren
Copy link

Hello there,

I have an nginx config file as below. The Config file also has multiple location settings. When I want to do this with Puppet I get a duplicate error. Am I doing something wrong? Or does puppet not support multiple locations?

I have many conf files for other domains.. Each has a lot of location definitions. I'm still investigating. But I did not find anyone else wanting to use it this way.

My production host conf;

server {
  listen *:80;

  server_name           test.example1.com;

  index  index.html index.htm index.php;
  access_log            /var/log/nginx/test.example.com.access.log combined;
  error_log             /var/log/nginx/test.example.com.error.log;

  location / {
    index     index.html index.htm index.php;
    return https://$host$uri$is_args$args;
  }

  location /example2 {
    proxy_pass            http://example2.com;
    proxy_read_timeout    90s;
    proxy_connect_timeout 90s;
    proxy_send_timeout    90s;
    proxy_set_header	  Host $host;
    proxy_set_header	  X-Real-IP $remote_addr;
    proxy_set_header	  X-Scheme $scheme;
    proxy_set_header	  X-Forwarded-For $proxy_add_x_forwarded_for;
  }

  location /example3 {
    proxy_pass            http://example3.com;
    proxy_read_timeout    90s;
    proxy_connect_timeout 90s;
    proxy_send_timeout    90s;
    proxy_set_header	  Host $host;
    proxy_set_header	  X-Real-IP $remote_addr;
    proxy_set_header	  X-Scheme $scheme;
    proxy_set_header	  X-Forwarded-For $proxy_add_x_forwarded_for;
  }

  location /example4 {
    proxy_pass            http://example4.com;
    proxy_read_timeout    90s;
    proxy_connect_timeout 90s;
    proxy_send_timeout    90s;
    proxy_set_header	  Host $host;
    proxy_set_header	  X-Real-IP $remote_addr;
    proxy_set_header	  X-Scheme $scheme;
    proxy_set_header	  X-Forwarded-For $proxy_add_x_forwarded_for;
  }    
}

Puppet nginx.pp conf;

node 'nginx-server' {

class { 'nginx':
  worker_connections => 2048,
  worker_rlimit_nofile => 8192,
  worker_processes => 2,
  server_tokens => off,
  ssl_stapling => 'on',
}

nginx::resource::server { 'test.example1.com':
  server_name => ['test.example1.com' ],
  listen_port => 80,
  use_default_location => false,
}

nginx::resource::location { "test.example1.com":
      server    => 'test.example1.com',
      ensure    => present,
      location  => '/example2',
      proxy     => "http://example2.com",
}

nginx::resource::location { "test.example1.com":
      server    => 'test.example1.com',
      ensure    => present,
      location  => '/example3',
      proxy     => "http://example3.com",
}
}

## Versions:

  • Puppet:
    Server;
    [root@puppet-server]# yum list installed |grep puppet
    puppet-agent.x86_64 5.5.1-1.el7 @puppet5
    puppet5-release.noarch 5.0.0-1.el7 installed
    puppetlabs-release.noarch 22.0-2 installed
    puppetlabs-release-pc1.noarch 1.1.0-5.el7 installed
    puppetserver.noarch 5.3.1-1.el7 @puppet5
    ruby-shadow.x86_64 1:2.2.0-2.el7 @puppetlabs-deps
    Agent;
    [root@nginx-server]# puppet --version
    5.5.1

  • OS: CentOS Linux release 7.4.1708 (Core)

  • Module version: 0.12.0

My Output log

[root@nginx-server]# puppet agent -t
Info: Using configured environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Retrieving locales
Info: Loading facts
Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Resource Statement, Duplicate declaration: Nginx::Resource::Location[test.example1.com] is already declared at (file: /etc/puppetlabs/code/environments/production/manifests/nginx.pp, line: 46); cannot redeclare (file: /etc/puppetlabs/code/environments/production/manifests/nginx.pp, line: 53) (file: /etc/puppetlabs/code/environments/production/manifests/nginx.pp, line: 53, column: 1) on node nginx-server
Warning: Not using cache on failed catalog
Error: Could not retrieve catalog; skipping run
@pfflaren
Copy link
Author

is there anyone who can support?

@wqbbs911
Copy link

i got same issue before ,looks like "location => /XXX" should set same value as "nginx::resource::location { XXX", like:
nginx::resource::location { "test.example1.com":
server => 'test.example1.com',
ensure => present,
location => '/test.example1.com',
proxy => "http://example3.com",
}

or like this

nginx::resource::location { "example3":
server => 'test.example1.com',
ensure => present,
location => '/example3',
proxy => "http://example3.com",
}

@sramesh123
Copy link

It is due to the same location name "test.example1.com" is used multiple times. Just change it as below,

nginx::resource::location { "test.example1.com-example2":
server => 'test.example1.com',
ensure => present,
location => '/example2',
proxy => "http://example2.com",
}

nginx::resource::location { "test.example1.com-example3":
server => 'test.example1.com',
ensure => present,
location => '/example3',
proxy => "http://example3.com",
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants