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

Add rewrite_to_https_port setting support #789

Closed
wants to merge 1 commit into from

Conversation

invidian
Copy link

In situation, when nginx is behind port multiplexer, ex. sslh, so nginx ssl is listening on 8443 and multiplexer on 443, I was unable to set proper redirect to SSL. With this patch, we can set on which port we want to be redirected to SSL.

First if in template is to prevent using @ssl_port when @rewrite_to_https_port is defined. Second if is the same as for @ssl_port

@invidian invidian force-pushed the rewrite-to-https-port branch from f8d0e96 to a23047c Compare May 12, 2016 17:49
@invidian invidian force-pushed the rewrite-to-https-port branch from a23047c to 25b1f4b Compare May 12, 2016 18:38
@bastelfreak
Copy link
Member

Hi @invidian, can you add tests for this PR?

@wyardley wyardley added the enhancement New feature or request label Oct 28, 2016
@wyardley
Copy link
Collaborator

I'm in favor of this, but just wondering, what do people think about changing the name of the rewrite_to_https_port that's easier for people to find when searching for TLS / SSL related directives, say:
ssl_force_redirect or similar? To me, 'redirect' and 'ssl' would probably be the things I'd look for first, and I'd expect it to be clustered along with the SSL related directives.

@invidian: are you able to add tests and are you still interested in pushing this PR along? If not, I can take my best stab at reworking it when there's time, but no promises.

@invidian
Copy link
Author

Hi, sorry for not updating for a long time. Unfortunately, I'm not familiar with unit test, so I can't provide them until I find time to learn how to do it. But I just ticked "Allow edits from maintainers", so you should be able to push tests to that PR.

That would be nice to push this PR, as it covers missing functionality, which is quite often used in my opinion.

In my opinion, renaming it to ssl_force and ssl_force_port might be a good idea, but it's up to you.

@wyardley
Copy link
Collaborator

It would mostly be modifying this test: https://github.com/voxpupuli/puppet-nginx/blob/master/spec/defines/resource_vhost_spec.rb#L234
I'll leave this open for now, if I get a chance later, I'll try to make a replacement PR that handles this and renames both variables.

@wyardley
Copy link
Collaborator

wyardley commented Nov 1, 2016

The interesting thing is that this already seems to be there in vhost_ssl_header.erb

  if ($ssl_protocol = "") {
       return 301 https://$host<% if @ssl_port.to_i != 443 %>:<%= @ssl_port %><% end %>$request_uri;

So I think if @ssl_port is set, this will already behave as you expect.

@law
Copy link

law commented Nov 1, 2016

In general, nginx frowns upon using 'if' statements, per:
https://www.nginx.com/resources/wiki/start/topics/depth/ifisevil/

They also have a recommended 'force-http-to-https' config statement, per:
https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/#taxing-rewrites

Given that, perhaps there should be a more stringent "force_all_to_ssl" or similar option? That would replace the previous if-statement and various :80 stanzas to just use:

{
  listen *:80;
  server_name           myvhostname;
  return 301 https://$host$request_uri;
}

@wyardley
Copy link
Collaborator

wyardley commented Nov 1, 2016

@invidian: rereading, and I see what you're saying now, I'll try to add this to my rework as well.

@wyardley wyardley closed this Nov 1, 2016
@wyardley wyardley reopened this Nov 1, 2016
@invidian
Copy link
Author

invidian commented Nov 1, 2016

@wyardley Thank you for your effort resolving this. Your pull request looks good, I hope you will be able to finish it.

@wyardley
Copy link
Collaborator

wyardley commented Nov 2, 2016

@invidian: thanks -- take a look, I've made some additional changes.
I didn't include the previous commits from this PR since I reworked the logic quite a bit; hope that's Ok if that one ends up getting merged instead.

@invidian
Copy link
Author

invidian commented Nov 3, 2016

#957 looks OK. Feel free to close that one if your PR gets merged.

@wyardley
Copy link
Collaborator

wyardley commented Nov 9, 2016

This functionality now exists in the (merged) #957

@wyardley wyardley closed this Nov 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request needs-tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants