Nginx
很简单就可以解决同一台机器同时跑两个或者多个项目,而且都通过域名从80端口走。
以Windows
环境下nginx
服务为例,配置文件nginx.conf
中,http
中加上
include /setup/nginx-1.20.1/conf/conf.d/*.conf;
删除server
部分,完整如下:
#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;
#access_log logs/access.log main;
include /setup/nginx-1.20.1/conf/conf.d/*.conf;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
}
在/setup/nginx-1.20.1/conf/conf.d/
目录下创建hquw365.conf
、hqxg365.conf
文件。
hquw365.conf
配置如下:
server {
listen 80;
server_name beian.hquw365.com;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root D:/setup/nginx-1.20.1/html/beian/hquw365;
index index.html index.htm;
}
#error_page 404 /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;
}
}
hqxg365.conf
配置如下:
server {
listen 80;
server_name hqxg365.com;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root D:/setup/nginx-1.20.1/html/beian/hqxg365;
index index.html index.htm;
}
#error_page 404 /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;
}
}
配置完成后,重新加载nginx
配置文件。
在浏览器中输入http://beian.hquw365.com/
输入http://hqxg365.com/
实际应用中,可以将两个域名都解析到同一台服务器上,然后如此配置,即可实现同一台服务器部署两个项目,都走80端口。