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

How to implement return 301 and listen *:80 default directives #979

Closed
rdev5 opened this issue Nov 24, 2016 · 4 comments
Closed

How to implement return 301 and listen *:80 default directives #979

rdev5 opened this issue Nov 24, 2016 · 4 comments
Labels

Comments

@rdev5
Copy link
Contributor

rdev5 commented Nov 24, 2016

Hi,

Just need to know how I can do the following with this module:

Load default site (no vhost found):

server {
  listen *:80 default;
  server_name           _;
}

Redirect non-SSL with 301:

server {
	listen 80;
	server_name example.com;
	return 301 https://$host$request_uri;
}
@wyardley
Copy link
Collaborator

You can use _ as a literal in the server_name parameter (which can take an array or string), so in a simple use case, you can just set the server_name parameter to _.

With current version, you can just define the vhost once and define the ssl_redirect parameter. There are a couple other ssl_ options, see the limited docs that are there now, as well as the parameters documented for the vhost resource: https://github.com/voxpupuli/puppet-nginx/blob/master/manifests/resource/vhost.pp

@ardrigh
Copy link
Contributor

ardrigh commented Feb 28, 2017

I have been trying to create a similar server setting for a Confluence install.
I created this manual configuration which I have been using this module to create:

Puppetfile:

mod "puppet/nginx", "0.6.0"

Manual configuration:

  server {
      listen 80 default_server;
      server_name wiki.foo.lan;

      return         301 https://$server_name/;
  }

Yaml for this module:

nginx::nginx_servers:
  '_':
    ensure: 'present'
    listen_options: 'default_server'
    listen_port: 80
    ssl: false
    ssl_redirect: true
    use_default_location: false

Output from the yaml:

$ cat _.conf 
# MANAGED BY PUPPET
server {
  listen *:80 default_server;
  server_name           _;

  return 301 https://$host$request_uri;
  access_log            /var/log/nginx/_.access.log combined;
  error_log             /var/log/nginx/_.error.log;
}

Hopefully the yaml example may help anyone else reading this ticket.

Without the use_default_location: true option this module has a bug causing nginx to fail to restart.

@noni73
Copy link

noni73 commented Mar 3, 2017

The url for vhost resource is changed in PR#980 to server resource https://github.com/voxpupuli/puppet-nginx/blob/master/manifests/resource/server.pp

@wyardley
Copy link
Collaborator

I'm going to close this; reopen if any more help is needed.

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

No branches or pull requests

5 participants