Force HTTPS redirect

Permanent redirect all HTTP traffic to HTTPS

server { listen 80; return 301 https://$host$request_uri; }

tool
nginx15 commands
tags
nginxsecurity

More nginx commands

  • curl -s http://localhost/stub_status

    Built-in nginx status page: active, reading, writing, waiting

  • deny 192.168.1.0/24; deny 10.0.0.1; allow all;

    Block a subnet and specific IP in nginx location/server block

  • location /ws/ { proxy_pass http://backend; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; }

    WebSocket proxy with required Upgrade headers

  • nginx -t

    Validate nginx.conf without reloading

  • nginx -s reload

    Gracefully reload config — zero connection drop

all 15 nginx commands