NGINX同时监听多个80端口匹配多个域名(Linux服务器)
NGINX同时监听多个80端口匹配多个不同的域名,多个域名同时监听80端口结果被覆盖,NGINX代理多个vue项目
·
1. 背景
最近给刚毕业工作的学设计的对象写了一个计算器打卡的网站,申请了新的二级域名
,上传到了自己之前的服务器,结果发现自己服务器nginx
对应的其它的80端口都被这个新的二级域名覆盖了。最后用了5个小时左右的时间解决了,记录以防止再犯。
2. 思路要点
- vue的
history
打包项目 - 可以利用
server_name
- @和
www
域名中间要用空格隔开, @和www域名中间要用空格隔开, @和www域名中间要用空格隔开。
3. Nginx详细配置
user root root;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 128;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
# 开启gzip
gzip on;
# 低于1kb的资源不压缩
gzip_min_length 1k;
# 设置压缩所需要的缓冲区大小
gzip_buffers 4 16k;
# 压缩级别【1-9】,越大压缩率越高,同时消耗cpu资源也越多,建议设置在4左右。
gzip_comp_level 8;
# 需要压缩哪些响应类型的资源,缺少自己补。
gzip_types text/css text/javascript application/javascript image/gif;
# 配置禁用gzip条件,支持正则。此处表示ie6及以下不启用gzip(因为ie低版本不支持)
gzip_disable "MSIE [1-6]\.";
# 是否添加“Vary: Accept-Encoding”响应头,
gzip_vary on;
server {
listen 80;
server_name a.main.xyz www.a.main.xyz;
# 开启gzip
#gzip on;
# 低于1kb的资源不压缩
#gzip_min_length 1k;
# 设置压缩所需要的缓冲区大小
#gzip_buffers 4 16k;
# 压缩级别【1-9】,越大压缩率越高,同时消耗cpu资源也越多,建议设置在4左右。
#gzip_comp_level 8;
# 需要压缩哪些响应类型的资源,缺少自己补。
#gzip_types text/css text/javascript application/javascript image/gif;
# 配置禁用gzip条件,支持正则。此处表示ie6及以下不启用gzip(因为ie低版本不支持)
#gzip_disable "MSIE [1-6]\.";
# 是否添加“Vary: Accept-Encoding”响应头,
#gzip_vary on;
location /nclockin/ {
proxy_pass http://localhost:3969/;
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;
}
location /week {
alias /root/songtang/nclockin/client/ai/happybirthday;
try_files $uri $uri/ /index.html;
index index.html;
}
location / {
root /root/songtang/nclockin/client/dist;
index index.html index.htm;
try_files $uri $uri/ /index.html;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
server {
listen 80;
server_name b.main.xyz www.b.main.xyz;
location / {
root /root/songtang/nknowledge/client/dist;
index index.html index.htm;
try_files $uri $uri/ /index.html;
proxy_redirect off;
}
location /nknowledge/ {
proxy_pass http://localhost:3966/;
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;
}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
更多推荐
已为社区贡献1条内容
所有评论(0)