当前位置:首页 > 编程笔记 > 正文
已解决

Nginx:不同域名访问同一台机器的不同项目

来自网友在路上 175875提问 提问时间:2023-11-12 18:47:00阅读次数: 75

最佳答案 问答题库758位专家为你答疑解惑

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.confhqxg365.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端口。

查看全文

99%的人还看了

猜你感兴趣

版权申明

本文"Nginx:不同域名访问同一台机器的不同项目":http://eshow365.cn/6-38330-0.html 内容来自互联网,请自行判断内容的正确性。如有侵权请联系我们,立即删除!