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

A redirect-only vhost #370

Closed
zachfi opened this issue Jul 1, 2014 · 14 comments
Closed

A redirect-only vhost #370

zachfi opened this issue Jul 1, 2014 · 14 comments
Labels
enhancement New feature or request

Comments

@zachfi
Copy link
Contributor

zachfi commented Jul 1, 2014

We're in the process of evaluating this module instead of our own for various reasons, but I am having trouble reproducing a config that we use pretty commonly. I'm willing to add support if it turns out thats required, but I thought I'd ask if there was a clean way to do this with the module in its current form.

First, here is the resulting vhost I am trying to produce.

server {
  listen   *:80;
  server_name sitea.example.com;
  rewrite ^/(.*) http://siteb.example.com/$1 permanent;
}

So here there are no locations, no other resources, just receive requests on sitea.example.com and redirect them to siteb.example.com. Pretty simple.

Now the manifest I tried to work out to do this.

  nginx::resource::vhost { 'sitea.example.com':
    use_default_location => false,
    index_files          => [],
    location_custom_cfg  => {},
    rewrite_rules        => [
      '^/(.*) http://siteb.example.com/$1 permanent',
    ],
  }

I'm willing to suspend my annoyance at the lack of brevity required here, but this doesn't do what I need, since the rewrite_rules[] only exists within the location blocks. Nginx supports the ability to have rewrite rules in the server blocks, so it seems to me that the module should also support this.

Is there a way that those more experienced with this module can think of to produce the desired state with what exists today? If so, how? If not, what would be the best approach I could take to add support?

I was thinking some kind of rewrite_only for nginx::resource::vhost, but from what I can tell that class seems to revolve around a location based server resource block.

Any insight would be appreciated.

Cheers.

@jfryman
Copy link
Contributor

jfryman commented Jul 11, 2014

@xaque208 You're spot on. Right now, the rewrite rules are only in the location block. PR's most certainly accepted.

@ShonM
Copy link

ShonM commented Oct 15, 2014

I'm interested in this - from what I can see it's not possible. Can anyone confirm that? I'm going to keep looking, and maybe submit a PR this week

@guzmanbraso
Copy link
Contributor

I think It's possible to have a setup like that with today features but maybe sure it's not friendly, something like this should do the trick:

nginx::resource::vhost { 'sitea.example.com':
    use_default_location => false,
    index_files          => [],
    location_custom_cfg  => {},
    vhost_cfg_append     => {
        'rewrite'      => '^/(.*) http://siteb.example.com/$1 permanent'
    }
}

@tim-massey
Copy link

Thanks, works for me 👍 .

@3flex 3flex added the enhancement New feature or request label Apr 13, 2015
@khaefeli
Copy link

I think this rewrite solutions are bad at all.
see: http://wiki.nginx.org/Pitfalls

why not providing a nginx::ressource::vhost with a scheme 301 redirect?

server {
  server_name www.domain.com;
  return 301 $scheme://domain.com$request_uri;
}

or:

 return 301 http://domain.com$request_uri;

instead of:

rewrite ^/(.*)$ http://domain.com/$1 permanent;

@levpaul
Copy link

levpaul commented Sep 17, 2015

I also want something like @khaefeli is suggesting. Any updates on providing this?

@joshuagordondba
Copy link

I have done this unfortunately, I am not at work but hope to remember to
update this on Monday. It was not east to figure out perhaps this should be
added as an option.
On Sep 16, 2015 10:41 PM, "Levi Lovelock" notifications@github.com wrote:

I also want something like @khaefeli https://github.com/khaefeli is
suggesting. Any updates on providing this?


Reply to this email directly or view it on GitHub
#370 (comment)
.

@j4ybee
Copy link

j4ybee commented Apr 18, 2016

@joshuagordondba it's Monday today, even though a few month later ;) , so I wanted to send a little reminder as I am very interested in your solution!

@bernhardjt
Copy link

What do you think of #774 ?

@wyardley
Copy link
Collaborator

wyardley commented Oct 7, 2016

Sorry for the lack of discussion / merge for this. I will comment in #774

@wyardley
Copy link
Collaborator

wyardley commented Nov 2, 2016

It would be nice to have the way to do a return and suppress the rest of the configs in the vhost, similar to what we do with the SSL rewrite or when ssl_only is set....

@NimishKmr
Copy link

Hello,
Do we have a solution for this. I am need of this as we have to redirect our old site to new site. And my nginx puppet config is a bit complex. We have multiple websites and we have manifest files where we provide server_name, port, mage_run_code, etc. I would like to add redirect/rewrite rule in this manifest for a particular site. How to achieve this?

@h0tw1r3
Copy link

h0tw1r3 commented May 13, 2020

I think this should be closed.
Solution with puppet/nginx 1.0.0:

nginx::resource::server { 'somewhere.old':
  maintenance       => true,
  maintenance_value => 'return 301 $scheme://somewhere.new$request_uri',
}

@ekohl
Copy link
Member

ekohl commented May 13, 2020

Thanks!

@ekohl ekohl closed this as completed May 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests