首先安装配置环境nginx
- cd 到nginx的site-available目录 ubuntu的在
cd /etc/nginx/site-enabled/
- 创建一个server文件
sudo touch testServer
- 复制下面的文件
server {
listen 80;
server_name your-site; # 这里填写域名,做http -> https指向
rewrite ^(.*)$ https://${server_name}$1 permanent;
}
server {
listen 443;
server_name your-site;
charset utf-8;
client_max_body_size 75M;
ssl on;
ssl_certificate /url-to-your-crt;
ssl_certificate_key /url-to-your-key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers AESGCM:ALL:!DH:!EXPORT:!RC4:+HIGH:!MEDIUM:!LOW:!aNULL:!eNULL;
ssl_prefer_server_ciphers on;
# js路径
location /js {
alias /url-to-your-js;
}
# css样式路径
location /css {
alias /url-to-your-css;
}
# 图片路径
location /img {
alias /url-to-your-img;
}
# fonts 路径
location /fonts {
alias /url-to-your-fonts;
}
# 网站项目根路径
root /url-to-your-site-root;
location / {
try_files $uri $uri/ /index.html; # 这里不要改,兼容前端单页面router-history模式
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_redirect off;
}
}
- 重启nginx
sudo service nginx restart
网友评论