How to set up Nginx HTTP to HTTPS redirection (Default settings)

In case You decide to use this example, place the two config files separately inside /etc/nginx/sites-available and create a symlink for them inside /etc/nginx/sites-enabled (please temporarily remove symlink for your previous configs inside /etc/nginx/sites-enabled . No need to remove them completely)

1. First file name "Default"

  1. server {

  2. listen 80 default_server;

  3. listen [::]:80 default_server;

  4. server_name Your_server_address.com

  5. return 301 https://$host$request_uri;

  6. location /{

  7. proxy_pass http://localhost:3000;

  8. proxy_http_version 1.1;

  9. proxy_set_header Upgrade $http_upgrade;

  10. proxy_set_header Connection "upgrade";

  11. proxy_set_header Host $http_host;

  12. proxy_cache_bypass $http_upgrade;

  13. }

  14. }

2. Second file name "https.conf"

  1. # HTTPS Server

  2. server {

  3. listen 443 ssl;

  4. server_name Your_server_address.com;

  5. # You can increase the limit if your need to.

  6. client_max_body_size 200M;

  7. error_log /var/log/nginx/rocketchat.access.log;

  8. ssl_certificate your full cheined certificate location

  9. ssl_certificate_key your SSL certificate key location

  10. ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # dont use SSLv3 ref: POODLE

  11. location / {

  12. proxy_pass http://localhost:3000;

  13. proxy_http_version 1.1;

  14. proxy_set_header Upgrade $http_upgrade;

  15. proxy_set_header Connection "upgrade";

  16. proxy_set_header Host $http_host;

  17. proxy_cache_bypass $http_upgrade;

  18. }

  19. }

Last updated