I am try to redirect anything going to port 80 and 8080 to 443 (https) using nginx. This is for a Jenkins server. I am using ubuntu. This is the nginx config I have at the moment:
server { listen 80; server_name jenkins.mydomain.com; location / { proxy_pass http://localhost:8080; proxy_set_header Host $host; proxy_redirect http://localhost:8080 https://jenkins.mydomain.com; } return 301 https://jenkins.mydomain.com$request_uri; } server { listen [::]:443 ssl ipv6only=on; listen 443 ssl; server_name jenkins.mydomain.com; ssl on; ssl_certificate /path/to/wildcard.mydomain.com.crt; ssl_certificate_key /path/to/wildcard.mydomain.com.key; location / { add_header Cache-Control private; expires epoch; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto https; proxy_set_header Host $host; proxy_ssl_protocols TLSv1 TLSv1.1 TLSv1.2; proxy_ssl_server_name on; include /etc/nginx/proxy_params; proxy_pass http://localhost:8080; proxy_read_timeout 90s; proxy_redirect http://localhost:8080 https://jenkins.mydomain.com; } } As you can see I tried adding the proxy related headers to the port 80 server block but that is not working. When I go to http://jenkins.mydomain.com or http://jenkins.mydomain.com:8080 it does not redirect to https://jenkins.mydomain.com. How do I redirect anything going to port 80 and 8080 to 443?