How i force https?


  • Gamers

    How i force https my NGINX

    My Nginx settings

    server {
      listen [::]:443 ssl http2;
      listen 443 ssl http2;
      listen [::]:80;
      listen 80;
      
      server_name javahub.de;
      
    
      client_max_body_size 50M;
    
      # RSA
      ssl_certificate /etc/letsencrypt/javahub.de/fullchain.pem;
      ssl_certificate_key /etc/letsencrypt/javahub.de/private.key;
      # ECDSA
      ssl_certificate /etc/letsencrypt/javahub.de_ecc/fullchain.pem;
      ssl_certificate_key /etc/letsencrypt/javahub.de_ecc/private.key;
    
      location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;
        proxy_pass http://127.0.0.1:4567;
        proxy_redirect off;
        # Socket.IO Support
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade"; 
      }
    
    }
    
    

  • Global Moderator

    Remove the listen 80 parts.



  • Like this:

    server {
      listen [::]:80;
      listen 80;
      server_name javahub.de www.javahub.de;
      return 301 https://javahub.de$request_uri;
    }
    
    server {
      listen [::]:443 ssl http2;
      listen 443 ssl http2;
      
      server_name javahub.de;
    
      client_max_body_size 50M;
    
      # RSA
      ssl_certificate /etc/letsencrypt/javahub.de/fullchain.pem;
      ssl_certificate_key /etc/letsencrypt/javahub.de/private.key;
      # ECDSA
      ssl_certificate /etc/letsencrypt/javahub.de_ecc/fullchain.pem;
      ssl_certificate_key /etc/letsencrypt/javahub.de_ecc/private.key;
    
      location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;
        proxy_pass http://127.0.0.1:4567;
        proxy_redirect off;
        # Socket.IO Support
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade"; 
      }
    
    }
    
    


  • hello you can create two separate vhosts for 80 and 443 and add redirect to htttps in http (port 80) vhost

    rewrite ^(.*)$ https://www.$host$1 permanent;
    

    or

    return   301 https://$server_name$request_uri;
    

Log in to reply
 

Suggested Topics

| |