一、nginx.conf文件配置

  1. server {
  2. listen 80;
  3. server_name 域名地址; # 你的域名地址
  4. #rewrite ^(.*)$ https://${server_name}$1 permanent;
  5. location /{
  6. proxy_pass http://127.0.0.1:6677/; #你的项目地址
  7. proxy_set_header Host $http_host;
  8. proxy_set_header X-Real-IP $remote_addr;
  9. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  10. proxy_set_header Upgrade $http_upgrade;
  11. #proxy_set_header Connection $connection_upgrade;
  12. }
  13. }
  14. #部署SSL证书HTTPS访问
  15. server {
  16. listen 443 ssl;
  17. server_name 你的域名地址;#你的域名地址
  18. #ssl on;
  19. root html;
  20. index index.html index.htm;
  21. ssl_certificate cert/你的pem证书.pem; ##此处的cert为conf文件下新建的cert文件专门用作存放证书文件
  22. ssl_certificate_key cert/你的key证书.key;
  23. ssl_session_timeout 5m;
  24. ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
  25. ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  26. ssl_prefer_server_ciphers on;
  27. location / {
  28. # root html;
  29. # index index.html index.htm;
  30. proxy_set_header Host $http_host;
  31. proxy_set_header X-Real-IP $remote_addr;
  32. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  33. proxy_pass http://127.0.0.1:6677; #你的项目地址
  34. proxy_redirect default;
  35. proxy_set_header Upgrade $http_upgrade;
  36. #proxy_set_header Connection $connection_upgrade;
  37. }
  38. }

说明: cert文件为放置证书的文件,位置位于nginx软件的conf文件夹下

总结

配置好项目代理地址,再向阿里云或者腾讯云申请SSL证书,下载之后放到指定的文件夹下,配置SSL访问