赞
踩
如果还没有安装 Nginx,可以使用包管理工具安装。例如,在 Ubuntu 上:
- sudo apt update
- sudo apt install nginx
将你的证书文件和私钥文件上传到服务器上的某个目录,比如 /etc/nginx/ssl/
。
编辑 Nginx 配置文件,通常位于 /etc/nginx/sites-available/your_site
。配置文件内容大致如下:
- server {
- listen 80;
- server_name your_domain.com www.your_domain.com;
- return 301 https://$server_name$request_uri; # 重定向 HTTP 到 HTTPS
- }
-
- server {
- listen 443 ssl;
- server_name your_domain.com www.your_domain.com;
-
- ssl_certificate /etc/nginx/ssl/your_certificate.crt;
- ssl_certificate_key /etc/nginx/ssl/your_private_key.key;
- ssl_trusted_certificate /etc/nginx/ssl/your_intermediate_certificate.crt;
-
- ssl_protocols TLSv1.2 TLSv1.3;
- ssl_ciphers HIGH:!aNULL:!MD5;
- ssl_prefer_server_ciphers on;
-
- location / {
- proxy_pass http://localhost:your_app_port; # 代理到你的应用服务器
- proxy_set_header Host $host;
- 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;
- }
- }
测试配置是否正确:
- sudo nginx -t
- sudo systemctl restart nginx
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。