Skip to content

Instantly share code, notes, and snippets.

@brycied00d
Created November 24, 2014 18:18
Show Gist options
  • Save brycied00d/564dbadead55dd3b8414 to your computer and use it in GitHub Desktop.
Save brycied00d/564dbadead55dd3b8414 to your computer and use it in GitHub Desktop.
nginx redirect to the FQDN with an alternative port
server {
listen 80; ## listen for ipv4; this line is default and implied
listen [::]:80 default_server ipv6only=on; ## listen for ipv6
server_name localhost; # A sane default, nobody cares
# The actual logic
set $this_host $host;
if ($host !~* "\.fqdn\.com$") {
#rewrite ^ https://$host.fqdn.com:8006$request_uri? permanent;
set $this_host "$host.fqdn.com";
}
rewrite ^ https://$this_host:8006$request_uri? permanent;
}
server {
listen 443 default_server;
listen [::]:443 default_server ipv6only=on;
server_name localhost; # A sane default, nobody cares
ssl on;
ssl_certificate /path/to/the.pem;
ssl_certificate_key /path/to/the.key;
ssl_session_timeout 1m;
ssl_protocols SSLv3 TLSv1;
ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv3:+EXP;
ssl_prefer_server_ciphers on;
# The actual logic
set $this_host $host;
if ($host !~* "\.fqdn\.com$") {
#rewrite ^ https://$host.fqdn.com:8006$request_uri? permanent;
set $this_host "$host.fqdn.com";
}
rewrite ^ https://$this_host:8006$request_uri? permanent;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment