参考:https://blog.csdn.net/a873217486/article/details/106097855

    阿里云域名配置https的参考例子:

    1. #user nobody;
    2. worker_processes 1;
    3. #error_log logs/error.log;
    4. #error_log logs/error.log notice;
    5. #error_log logs/error.log info;
    6. #pid logs/nginx.pid;
    7. events {
    8. worker_connections 1024;
    9. }
    10. http {
    11. include mime.types;
    12. default_type application/octet-stream;
    13. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
    14. # '$status $body_bytes_sent "$http_referer" '
    15. # '"$http_user_agent" "$http_x_forwarded_for"';
    16. #access_log logs/access.log main;
    17. sendfile on;
    18. #tcp_nopush on;
    19. #keepalive_timeout 0;
    20. keepalive_timeout 65;
    21. #gzip on;
    22. server {
    23. listen 80;
    24. listen 443 ssl;
    25. server_name 域名.com www.域名.com;
    26. root html;
    27. index index.html index.htm;
    28. ssl_certificate cert/域名申请的ssl证书的文件.com.pem;
    29. ssl_certificate_key cert/域名申请的ssl证书的文件.com.key;
    30. ssl_session_timeout 5m;
    31. ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
    32. ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    33. ssl_prefer_server_ciphers on;
    34. if ($http_user_agent ~* "Go-http-client/1.1" )
    35. { return 403; }
    36. # 反向代理新后台接口服务
    37. location /apis {
    38. rewrite ^/apis/(.*)$ /$1 break;
    39. proxy_pass http://127.0.0.1:9001;
    40. proxy_set_header Upgrade $http_upgrade;
    41. proxy_set_header Connection "upgrade";
    42. }
    43. location / {
    44. alias /home/wwwroot/default/dist/; #默认访问vue静态文件目录(dist路径)
    45. index index.html; #默认访问文件
    46. try_files $uri $uri/ /index.html; #目录不存在则执行index.html
    47. }
    48. }
    49. #可选配置,配置http重定向到https
    50. #server
    51. #{
    52. # listen 80;
    53. # server_name zilvren.com www.zilvren.com;
    54. # rewrite ^(.*)$ https://$host$1 permanent; #将所有http请求通过rewrite重定向到https。
    55. # location / {
    56. # alias /home/wwwroot/default/dist/; #默认访问vue静态文件目录(dist路径)
    57. # index index.html; #默认访问文件
    58. # try_files $uri $uri/ /index.html; #目录不存在则执行index.html
    59. # }
    60. #}
    61. }

    如果阿里云的域名需要www和https的DNS的话,则这两种方式都需要在阿里云的域名DNS解析器中配置