查看: 40|回覆: 0

一台服务器通过nginx配置多个域名(80端口)

[複製鏈接]

4

主題

0

回帖

0

積分

热心网友

金币
0
閲讀權限
220
精華
0
威望
0
贡献
0
在線時間
0 小時
註冊時間
2009-3-7
發表於 2019-7-13 22:51:00 | 顯示全部樓層 |閲讀模式

1. 问题描述

多个域名对应一个服务器,为了避免域名后增加端口号,两个域名都需要占用80端口号,使用nginx来进行配置。

2. 解决方案

目前项目中,线上正在使用(100%可用)多域名对应一个服务器情况(线上ip及域名替换了下)

#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.hbusy.com; 

        location / {
            root   html;
            index  index_test1.html index_test1.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
     
     upstream visitip{
        server 192.168.0.11:3107;
     }    
    server {
        listen       80;
        server_name  test2.hbusy.com www.test2.hbusy.com;

        location / {
            proxy_pass   http://visitip;
            proxy_set_header Host $hostserver_port;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header REMOTE-HOST $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            client_max_body_size    2000m;

            proxy_connect_timeout 3600;
            proxy_send_timeout 3600;
            proxy_read_timeout 3600;
        }
    }
}

3. 方案说明

其实主要分两步:

第一步就是配置域名对应ip地址;第二就是在nginx中配置两个server(端口都为:80)。


回覆

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 立即注册

本版積分規則

相关侵权、举报、投诉及建议等,请发 E-mail:qiongdian@foxmail.com

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部