在linux系统部署项目时,通常会选择nginx进行项目的部署下面就把我的实际部署配置文件给大家分享下:
1: https 证书的配置 通常是监听 443端口,并配置对应的域名证书
server {
listen 443 ssl;
server_name www.youname.com; #改成你的域名
ssl_certificate /usr/local/nginx/ssl/server.crt; #证书路径
ssl_certificate_key /usr/local/nginx/ssl/server.key; #证书路径
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
set $Real $proxy_add_x_forwarded_for;
if ( $Real ~ (\d+)\.(\d+)\.(\d+)\.(\d+),(.*) ){
set $Real $1.$2.$3.$4;
}
proxy_set_header X-Real-Port $remote_port;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Headers *;
add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
client_max_body_size 1000m;
location / {
root /home/wwwroot/ceshi/dist; ##对应的项目访问路径
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
}
2.不带证书的
server {
listen 8887; #分配的端口号 监听
server_name www.ceshi.com 123.111.222.333:8888; ##直接设置解析的域名或者 ip+端口
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
set $Real $proxy_add_x_forwarded_for;
if ( $Real ~ (\d+)\.(\d+)\.(\d+)\.(\d+),(.*) ){
set $Real $1.$2.$3.$4;
}
proxy_set_header X-Real-Port $remote_port;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Headers *;
add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
client_max_body_size 1000m;
location / {
root /home/wwwroot/ceshi/dist;
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
}
标签:Real,文件,set,header,index,nginx,add,proxy,linux
From: https://blog.51cto.com/u_16170129/6657495