如下介紹了http和https的配置。html
首先一級域名的http所有重定向到https;nginx
server {
listen 80;
server_name example.com; #一級域名
rewrite ^ https://$http_host$request_uri? permanent;
}
複製代碼
設置web項目的域名、ssl正式位置以及配置、錯誤日誌路徑、默認頁面文件路徑。web
server {
listen 443 ssl;
ssl on;
server_name project.example.com; #二級域名指向頁面
ssl_certificate /ssl/project.example.com.pem;
ssl_certificate_key /ssl/project.example.com.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 10m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
access_log /var/log/nginx/project.log main;
location / {
index index.html;
root /home/root/project/dist;
}
}
複製代碼
設置server項目的域名、ssl證書位置以及配置、錯誤日誌路徑、端口配置。api
server {
listen 80;
listen 443 ssl;
server_name api.example.com;
ssl_certificate /ssl/api.example.com.pem;
ssl_certificate_key /ssl/api.example.com.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 10m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
access_log /var/log/nginx/api.log main;
location / {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-Ip $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://localhost:3000;
}
}
複製代碼
而後便可經過http://project.example.com
或者https://project.example.com
來訪問頁面。bash