nginx搭建域名反向代理服务器

周一公司要求给公司内的各个服务器使用二级域名,捣腾了三天今天重要弄出来了。

当前环境:

一个顶级域名 sxfenglei.com

一个固定IP   222.123.456.789

公司企业网站     192.168.1.10:80  路由映射 222.123.456.789:80

公司邮箱         192.168.1.11:80  路由映射 222.123.456.789:8080

公司OA           192.168.1.13:80  路由映射 222.123.456.789:8088


每次都是 www.sxfenglei.com        访问企业网站  

         www.sxfenglei.com:8080  访问邮箱  

         www.sxfenglei.com:8888  访问OA


需求:

现在老板要求,通过www.sxfenglei.com访问企业网,通过mail.sxfenglei.com访问邮箱,通过oa.sxfenglei.com访问OA


可是域名只能绑定IP而不能绑定端口,这可怎么办。找了许多资料发现原来反向代理可以实现,多个域名指向一个固定外网IP然后反向到局域网内不同的服务器上。


实现:

在192.168.1.10 win2003上 修改企业网站端口为888腾出80端口给nginx用 ,然后下载nginx并解压到e盘下 配置nginx.conf

找到server{}段

server {
       listen       80;     #这是监听本机 反向代理服务器192.168.1.10的80端口
       server_name  www.sxfenglei.com;
       location / {
           proxy_pass http://192.168.1.10:888/;     #这里配置代理就是当访问www.sxfenglei.com的时候反向到192.168.1.10:888企业网站上。
            proxy_redirect default;
       }
       error_page   500 502 503 504  /50x.html;
       location = /50x.html {
           root   html;
       }
   }
#可以添加多个
server {
       listen       80;     #这是监听本机 反向代理服务器192.168.1.10的80端口
       server_name  mail.sxfenglei.com;
       location / {
           proxy_pass http://192.168.1.11:80/;     #这里配置代理就是当访问www.sxfenglei.com的时候反向到192.168.1.11:80企业邮箱上。
            proxy_redirect default;
       }
       error_page   500 502 503 504  /50x.html;
       location = /50x.html {
           root   html;
       }
   }
server {
       listen       80;     #这是监听本机 反向代理服务器192.168.1.10的80端口
       server_name  oa.sxfenglei.com;
       location / {
           proxy_pass http://192.168.1.12:80/;     #这里配置代理就是当访问www.sxfenglei.com的时候反向到192.168.1.10:80企业OA上。
            proxy_redirect default;
       }
       error_page   500 502 503 504  /50x.html;
       location = /50x.html {
           root   html;
       }
   }


你可能感兴趣的:(nginx,反向代理服务器,二级域名配置反向代理)