我使用nginx作为我的node.js应用程序。 我已经使用Digitalocean教程来configurationnginx和https的使用。 现在,下面的工作:
http:// example.com – > https:// example.com
example.com – > https:// example.com
www.example.com – > https:// example.com
http:// www.example.com – > https:// example.com
但是当我inputhttps:// www.example.com时,它不会redirect到https:// example.com
这里是我的nginx congif网站,可用/默认
# HTTP - redirect all requests to HTTPS: server { listen 80; listen [::]:80 default_server ipv6only=on; return 301 https://$host$request_uri; } # HTTPS - proxy requests on to local Node.js app: server { listen 443; server_name ezplan.ir; ssl on; # Use certificate and key provided by Let's Encrypt: ssl_certificate /path/to.crt; ssl_certificate_key /path/to.key; ssl_session_timeout 5m; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; ssl_ciphers 'SSL STUFF'; # Pass requests for / to localhost:8080: location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-NginX-Proxy true; proxy_pass http://localhost:8080/; proxy_ssl_session_reuse off; proxy_set_header Host $http_host; proxy_cache_bypass $http_upgrade; proxy_redirect off; } }
任何人都可以帮助我做这个redirect?
您可以为https执行两个模块 – 使用和不使用www:
server { listen 443; server_name www.example.com; // ... return 301 https://example.com$request_uri; } server { listen 443; server_name example.com; // ... // your normal config here - proxy to node and all that }