
This Quickstart guide describes how to redirect non-secure HTTP requests to secure HTTPS on Nginx.
Locate your server block configuration file. By default, this is /etc/nginx/nginx.conf, however it's common for that file to have an include directive:
If you have a similar line, you may need to review several files in /etc/nginx/conf.d/ to locate the listen 80 (HTTP) server block for your site. You may have multiple blocks or files if you host multiple sites.
The basic steps are:
Adjust your listen 80 server block to redirect all traffic to HTTPS. Add a line similar to this:
Add a listen 443 ssl server block to handle the HTTPS traffic. Move any statements needed from your listen 80 server block to this new block.
Here is a simplified example of both blocks. Note that both http://example.com and http://www.example.com will redirect to https://example.com.
For more information about how to configure server blocks, see the Nginx documentation and this detailed nginx.conf example file.
0 Comments
Be the first to comment and share your perspective with the community.