Correct way in new versions of nginx
Turn out my first answer to this question was correct at certain time, but it turned into another pitfall – to stay up to date please check Taxing rewrite pitfalls
I have been corrected by many SE users, so the credit goes to them, but more importantly, here is the correct code:
server {
listen 80;
server_name my.domain.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
server_name my.domain.com;
# add Strict-Transport-Security to prevent man in the middle attacks
add_header Strict-Transport-Security "max-age=31536000" always;
[....]
}
Related Posts:
- WordPress redirect loop on nginx + apache reverse proxy
- Infinite loop behind SSL proxy on non-standard port
- Nginx + Redirection Plugin breaks Permalinks [closed]
- How to force or redirect to SSL in nginx?
- nginx HTTPS serving with same config as HTTP
- Nginx Redirect via Proxy, Rewrite and Preserve URL
- Remove “www” and redirect to “https” with nginx
- How can I use environment variables in Nginx.conf
- How to redirect all HTTP requests to HTTPS
- Nginx: Failed to start A high performance web server and a reverse proxy server
- How do you redirect HTTPS to HTTP?
- WordPress redirecting connections on port 8080 to 80
- Why is WordPress redirecting from http to https on a local environment?
- How to configure nginx to redirect requests to the uploads directory to the production server?
- Force HTTPS using .htaccess – stuck in redirect loop
- Keeps on redirecting on my development copy
- How to setup 301 redirects for multiple query string URLs?
- How to redirect url requests to https? [closed]
- Redirect www to non-www htaccess
- 302 redirect instead of 301 after switch to HTTPS
- How are both HTTP and HTTPS versions displaying?
- Redirect from https to http or from http to https? [closed]
- Mixed Content with SSL, wordpress behind a reverse proxy
- 302 redirect to signup with nginx reverse proxy
- NGINX conf on WP Multisite enabled — subdirectory — images fail to load after updates
- Configuring Routing Rules for WordPress+Nginx and WP-SuperCache?
- https redirect (with .htaccess) redirect loop
- Redirect HTTP to HTTPS
- REST API parameters not working with nginx
- How to set up htaccess to redirect a particular post type or subdirectory to HTTPS?
- Site redirecting from http to https [closed]
- Difference between these two nginx try_files statements for WordPress?
- How to test drive WordPress on VPS with LEMP stack before going live?
- Site kit Google Analytics setup giving Error: {“error”:”invalid ‘redirect_uri'”}
- nginx.conf appeared in all WordPress installations on folder
- What is the right way to redirect all traffic to HTTPS?
- wp_enqueue_style – CSS Not loading – ERR_TOO_MANY_REDIRECTS [closed]
- ERROR: No such service: nginx when building wordpress with docker [closed]
- Nginx tries the wrong file when http_cookie matches logged_in
- Htaccess file isn’t redirecting http sub-pages to https––they display 404 error instead, tried many solutions and none work
- Site resolves to www in Firefox and without in Chrome
- I get redirected too many times only in wp-admin?
- WordPress keeps redirecting subpages without http to https homepage after switch
- WordPress Nginx Won’t 404
- https – too many redirects
- Receiving 404 when uploading file larger than 10kb
- Too many redirects after added SSL redirect on port 80 virtual host
- ReDirect subfolder link to another sub-folder and force SSL
- Htaccess https 301 problem
- Limit file downloads to logged in users (WP + Nginx)
- Blog has an infinite redirect loop
- /blog/wp-json/ nginx return 404
- Moving wordpress to different url/server creates redirect loop
- WordPress CSS/Theme gone after SSL got activated
- My site doesn’t redirect from HTTP to HTTPS
- NGINX / WordPress Site – Increasing php.ini max_execution_time = 600 doesn’t work
- Only execute function if SSL is set up properly
- Admin sometimes redirects to HTTPS
- Nginx redirects to an extra subdirectory
- Something is injecting a slash after any static file response , server is nginx
- Custom permalinks not work on Nginx + Apache
- Last-Modified header is removed from server response!
- Redirecting specific sites to HTTP in WordPress Multisite
- 504 Gateway Time-out nginx/1.14.0 (Ubuntu)
- Redirect old /%category%/%postname%/ to just /%postname%/
- How to replace the links http to https
- why is my wordpress not loading any images?
- Can’t access WP-Admin via HTTPS
- Multisite wp-admin redirecting to main wp-admin using NGINX
- WordPress site not forcing from http to https instead getting redirected too many times
- Restrict access if logged out except for homepage
- Redirect HTTP request to HTTPS request
- How to force the admin-ajax.php file to load over HTTPS?
- Moving site from HTTP to HTTPS
- I have cloudflare flexible enabled, How to redirect to https for Nginx server
- Can I do fragment caching with NGINX fastcgi?
- Proxy caching WordPress with Nginx
- How to move a https website back to dev and access the admin?
- WordPress HTTPS – ‘… better to use HTTP for installation …’
- Nginx Multisite redirects (incorrectly) on Chrome IE and Mobile, but works (correctly) on Firefox
- Varnish + Nginx for WordPress is Good?
- Nginx reverse proxy + URL rewrite
- Nginx config reload without downtime
- How to output variable in nginx log for debugging
- connect() failed (111: Connection refused) while connecting to upstream
- Nginx 1 FastCGI sent in stderr: “Primary script unknown”
- Nginx: How do I forward an HTTP request to another port?
- How to restart nginx?
- How does try_files work?
- nginx – client request body is buffered to a temporary file
- Do you need separate IPv4 and IPv6 listen directives in nginx?
- Properly setting up a “default” nginx server for https
- How to make a modification take affect without restarting nginx?
- Nginx – root versus alias, for serving single files?
- Why do I need nginx when I have uWSGI
- Best way to redirect all HTTP to HTTPS in IIS
- Nginx redirect one path to another
- Loading WordPress Site Inside iframe won’t allow users to login
- How to force HTTP and stop SSL completey on WordPress website
- wordpress is auto using http: not https: as it needs to because the server is http behind a reverse proxy https, how do I stop it?