nginx反向代理配置一個域名映射到不同端口的項目

nginx反向代理配置一個域名映射到不同端口的項目

現在域名必須是綁定80端口,如果我們直接使用服務器的80端口發佈服務的話,需要外網訪問的項目都需要放到同一個web服務器下,

但是有些項目由於開發語言不同等等原因不能放在一個web服務器一起發佈,都有外網域名訪問的需求,使用nginx反向代理配置可以解決。

微信的H5鏈接必須域名才能正常訪問,其他端口的項目通過nginx映射即可

首先下載nginx  我下載的是1.13.1版本 下載後找到 ..\nginx\nginx-1.13.1\conf\nginx.conf配置文件 修改配置

我直接把我的配置貼出來 大家參考

#================begin=========================


#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  10;
 
    proxy_connect_timeout       10; 
   # proxy_read_timeout          1;
   # proxy_send_timeout          1;

    #gzip  on;


   server {
        listen       80; #這個nglnx監聽的端口 
        server_name  127.0.0.1:8098;  #這是我服務器上tomcat的8098端口

        location /wsyyPlatform {  #wsyyPlatform爲該tomcat發佈的項目

            proxy_pass   http://127.0.0.1:8098;
        }

        
        server_name  127.0.0.1:8085;#這是我服務器上tomcat的8085端口

        location /wsyy { #wsyy爲該tomcat發佈的項目

            proxy_pass   http://127.0.0.1:8085;
        }
        
       
    }
    
}
#================end=========================

相信大家看一下 server的配置已經知道怎麼配置了,

server_name  127.0.0.1:8098;  #這是我服務器上tomcat的8098端口

        location /wsyyPlatform {  #wsyyPlatform爲該tomcat發佈的項目

            proxy_pass   http://127.0.0.1:8098;
        }

要映射到的項目通過這幾行配置搞定。。。

 

 

window啓動nginx  
cmd  G:
cd G:\workSoft\nginx\nginx-1.13.1
啓動  start nginx
停止 nginx.exe -s stop

如果沒有nginx我們必須把wsyyPlatform,wsyy放到一個容器下發布 ,如果2個程序開發語言不同放一個容器發佈不了,

我這裏服務器域名爲pes.bsoft.com.cn,通過nginx反向代理配置後我們通過瀏覽器

訪問http://pes.bsoft.com.cn/wsyyPlatform會自動映射到http://127.0.0.1:8098/wsyyPlatform;

訪問http://pes.bsoft.com.cn/wsyy會自動映射到http://127.0.0.1:8085/wsyy

這個只有服務器有一個域名 我們可以把程序部署在多個容器 只要映射好可以通過域名訪問了,

 

 

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章