之前团队做了一个项目。该项目下有两个不同的子系统。客户想从域名这把两个子系统分开。相当于现在就有三个域名来访问这个项目。一个一级域名,直接访问项目的入口。两个二级域名,分别访问系统的两个子目录。同事问我是否需要部署三个不同的IIS服务器。我之前也没搞过.net。但我想,只要子系统的业务是解耦的,代码实现这块是隔离的,应该通过nginx的简单配置就能实现。我试着在nginx的配置文件里面做了一下,还真可以。这里把配置贴上来。
#user nobody;
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;
#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 on;
server {
listen 80;
server_name www.XXX.com; #一级域名
location / {
proxy_pass http://127.0.0.1:7081;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_next_upstream error timeout invalid_header http_500 http_503;
}
}
############################################
server {
listen 80;
server_name tender.XXX.com; #子系统一
location / {
proxy_pass http://127.0.0.1:7081/;
rewrite ^/$ /Tb/; #rewrite到相应的系统目录下
}
}
############################################
server {
listen 80;
server_name bid.XXX.com; #子系统二
location / {
proxy_pass http://127.0.0.1:7081/;
rewrite ^/$ /Zb/; #rewrite到相应的系统目录下
}
}
}