在一些小型服务器上,可能需要部署多个网站来合理利用服务器资源
比如 博客/小官网 等等
在同一个服务器,不同的域名共用80端口
Nginx 只需要在 server里配置好 server_name就好了
配置试例:
http {
... 上面省略
# 在码圈 博客
# 顶级域名 + ww二级域名
server {
listen 80;
server_name arcinbj.com www.arcinbj.com;
#charset koi8-r;
#access_log logs/host.access.log main;
#access_log "pipe:rollback logs/host.access_log interval=1d baknum=7 maxsize=2G" main;
error_page 404 /www/error/404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# 强制跳转http到https
rewrite ^(.*) https://$host$1 permanent;
}
# opsli 快速开发平台
# 顶级域名 + ww二级域名
server {
listen 80;
server_name opsli.com www.opsli.com;
#charset koi8-r;
#access_log logs/host.access.log main;
#access_log "pipe:rollback logs/host.access_log interval=1d baknum=7 maxsize=2G" main;
location / {
root html;
index index.html index.htm;
proxy_http_version 1.1;
# proxy_pass http://halo;
# 连接延时
proxy_connect_timeout 3600s;
proxy_read_timeout 3600s;
proxy_send_timeout 3600s;
# IP 穿透
proxy_set_header Host $proxy_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# WebSocket 穿透
proxy_set_header Origin "";
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
error_page 404 /www/error/404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# 强制跳转http到https
# rewrite ^(.*) https://$host$1 permanent;
}
}