1.阿里云申请下载SSL证书,上传到服务器 如何申请? 2.配置nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name xxxx.com www.xxxx.com;#访问域名
#自动跳转到HTTPS
return 301 https://$server_name$request_uri;
#文件大小限制,默认1m
client_max_body_size 20m;
#前端页面
location / {
root html/dist;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
#后台接口地址,前台项目请求加/prod-api/访问跳转到后台服务器处理请求
location /prod-api/{
proxy_pass http://127.0.0.1:7500/;
proxy_connect_timeout 15s;
proxy_send_timeout 15s;
proxy_read_timeout 15s;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
//配置HTTPS请求
server {
listen 443 ssl;#SSL默认访问路径
server_name xxxx.com www.xxxx.com;#访问域名
#文件大小限制,默认1m
client_max_body_size 20m;
ssl_certificate C:/nginx-1.20.0/cert/XXXXXX.pem;#证书路径
ssl_certificate_key C:/nginx-1.20.0/cert/XXXXXX.key;#密钥路径
#加密协议
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
#前端页面
location / {
root html/dist;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
#后台接口地址
location /prod-api/ {
proxy_pass http://127.0.0.1:7500/;
proxy_connect_timeout 15s;
proxy_send_timeout 15s;
proxy_read_timeout 15s;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
}
注意:配置成功后注意在阿里云安全组放行443端口
配置好之后就可以访问了
此时http与https都可以访问我们的网站了
|