我是靠谱客的博主 乐观山水,这篇文章主要介绍nginx配置多域名访问,现在分享给大家,希望可以做个参考。

  • 1. 本地添加模拟域名

在本地系统(windows)内找到C:WindowsSystem32driversetc下的hosts,在末尾添加如下内容

127.0.0.1 test1.com

127.0.0.1 test2.com

  • 2. 配置tomcat

配置两个tomcat,端口分别定为8888和9999,并启动

  • 3. 配置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;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  test1.com;

        location / {
           proxy_pass      http://localhost:8888;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
	
	server {
        listen       80;
        server_name  test2.com;

        location / {
           proxy_pass      http://localhost:9999;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

 

最后

以上就是乐观山水最近收集整理的关于nginx配置多域名访问的全部内容,更多相关nginx配置多域名访问内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(58)

评论列表共有 0 条评论

立即
投稿
返回
顶部