关于Nginx使用HTTPS部署多个前端项目解决办法
nginx.conf配置文件
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 600;
client_max_body_size 50m;
client_header_timeout 1m;
client_body_timeout 1m;
proxy_connect_timeout 60s;
proxy_read_timeout 1m;
proxy_send_timeout 1m;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml;
gzip_vary on;
gzip_proxied expired no-cache no-store private auth;
gzip_disable "MSIE [1-6]\.";
server_tokens off;
server {
listen 端口号;
server_name ip或者域名;
location / {
root /xxx/xxx/xxx;
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
location /app {
alias /xxx/xxx/xxx;
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
location /prod-api/{
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://ip:端口号/;
add_header 'Access-Control-Allow-Methods' 'GET,POST,PUT,DELETE';
add_header 'Access-Control-Allow-Headers' '*';
add_header 'Access-Control-Allow-Origin' 'http://43.136.245.22:8089' always;
add_header 'Access-Control-Allow-Credentials' 'true' always;
}
rewrite ^(.*)$ https://$host$1 permanent;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 443 ssl;
server_name 你自己的ip或者域名;
ssl_certificate /xxx/xxx/xxx;
ssl_certificate_key /xxx/xxx/xxx;
ssl_session_timeout 5m;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
location / {
root /xxx/xxx/xxx;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
location /app {
alias /xxx/xxx/xxx;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
location /prod-api/ {
proxy_pass http://ip:端口号/;
}
}
}