1. 程式人生 > >nginx配置子域名跳轉到後端請求

nginx配置子域名跳轉到後端請求

專案情況簡介:公司業務調整,新建子公司,專門做理財相關業務,對應需要分離出licai子站,但開發人員有限,最終定了主站和子站共用原始碼和TOMCAT伺服器,在NGINX上配置不同域名跳轉到對應後端請求。

環境簡介:全站https,兩個SLB,一個SLB對應uat.mydomain.com,另外一個SLB對應子站的licai.mydomain.com。

伺服器採用了NGINX做靜態快取和反向代理。新建子域名是直接配置DNS,指向對應的SLB.


對應的NGINX配置如下:

worker_processes  1;

events {
    use epoll;
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    log_format  uat.mydomain.com  '$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  uat.mydomain.com;

    sendfile        on;
    keepalive_timeout  600;

    upstream uat.mydomain.com { 
        server 127.0.0.1:8080; #可以根據需要修改
    } 

    upstream licai.mydomain.com { 
        server 127.0.0.1:8080; #可以根據需要修改
    } 
	
    #用於共享檔案
    server {
        listen       82;
        server_name  localhost;
        location / {
            root   /mnt/attachments;
            index  index.html index.htm;
        }
	}	
 
     server {
        listen      80;
        server_name  uat.mydomain.com licai.mydomain.com;	#80埠支援的域名
        client_header_buffer_size 128k;
        large_client_header_buffers 4 128k;
		#add_header Set-Cookie loginSessionHttp;
        location / {
            root   html;
            index  index.html index.htm;
	        rewrite ^(.*) https://$host$1 permanent;	#全站https
            proxy_buffer_size 64k;
            proxy_buffers   32 32k;
            proxy_busy_buffers_size 128k;
			proxy_set_header       Host $host;
            proxy_set_header  X-Real-IP  $remote_addr;
			proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
			proxy_set_header X-Forwarded-Proto  $scheme;
            client_max_body_size 50m;
            proxy_connect_timeout 360;
			port_in_redirect off;
			real_ip_header X-Forwarded-For;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    } 
	
    server {
        listen      443;
        server_name  uat.mydomain.com;
		client_header_buffer_size 128k;
        large_client_header_buffers 4 128k;
		add_header Set-Cookie loginSessionHttps;

        location / {
            root   html;
            index  index.html index.htm;
            proxy_buffers   32 32k;
            proxy_busy_buffers_size 128k;
            proxy_set_header       Host $host;
            proxy_set_header  X-Real-IP  $remote_addr;
            proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto  $scheme;
            client_max_body_size 50m;
            proxy_connect_timeout 360;
            port_in_redirect off;
            real_ip_header X-Forwarded-For; 
            proxy_pass http://uat.mydomain.com/;
         }

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

    }

    server {
        listen      445;
        server_name  licai.mydomain.com;
		client_header_buffer_size 128k;
        large_client_header_buffers 4 128k;
		add_header Set-Cookie loginSessionHttps;
	    port_in_redirect off; #防止跳轉的時候帶了埠號,會導致404
		
	    #對映圖片和資原始檔請求和主站一致
	    location ~ \.(css|js|gif|jpg|swf|png|htm|ico)$ {
		   proxy_pass http://licai.mydomain.com;
        }
		
	#如下幾條為了子站和主站公用後端程式碼
	location ~* /*financing* {
            proxy_pass http://licai.mydomain.com;
        }		

	location ~* /*login/login* {
            proxy_pass http://licai.mydomain.com;
        }
		
	location ~* /*login/logout* {
            proxy_pass http://licai.mydomain.com;
        }		
		
	location ~* /*userManage* {
            proxy_pass http://licai.mydomain.com;
        }		

	location ~* /*sendSmsCode* {
            proxy_pass http://licai.mydomain.com;
        }				

	#對映子域名到對應的後端請求
        location / {
            root   html;
            index  index.html index.htm;
            proxy_buffers   32 32k;
            proxy_busy_buffers_size 128k;
            proxy_set_header       Host $host;
            proxy_set_header  X-Real-IP  $remote_addr;
            proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto  $scheme;
            client_max_body_size 50m;
            proxy_connect_timeout 360;
            port_in_redirect off;
            real_ip_header X-Forwarded-For; 
            proxy_pass http://licai.mydomain.com/financing/; #對映子域名到對應的後端請求
         }

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

    }
}


相關推薦

nginx配置域名請求

專案情況簡介:公司業務調整,新建子公司,專門做理財相關業務,對應需要分離出licai子站,但開發人員有限,最終定了主站和子站共用原始碼和TOMCAT伺服器,在NGINX上配置不同域名跳轉到對應後端請求。 環境簡介:全站https,兩個SLB,一個SLB對應uat.mydo

Linux-Ubuntu環境安裝Nginx配置二級域名

前言:Centos和ubuntu環境的區別,可以檢視下nginx的配置檔案wheresi nginx顯示不同的目錄結構,本文主要講

Linux 下使用 Nginx 配置域名

使用 Nginx 的反向代理來解析子域名 下載並配置 Nginx yum install nginx vim /etc/nginx/nginx.cfg 配置示例: # 下面有中文註釋的地方是重點 us

ecs nginx 配置 http 自動到 https

1:在 http 模組中先配置所有的 http 訪問都跳轉到 https   server {         listen      80 default_server;      

nginx 配置https upstream 失敗

問題描述: 在配置完成nginx後,訪問就是無法實現代理,將proxy_pass配置成實際地址卻又是好的 解決方法: location / {     proxy_pass http://localhost;     proxy_set_header  Host 

nginx配置域名

gin 域名跳轉 cati include nginx 配置 roo perm 域名 ref nginx 配置主域名 xxx.com, 跳轉子域名 www.xxx.com server {listen 80;server_name www.xxx.com;

nginx配置域名到指定專案

   如www.abc.com跳轉到192.168.3.30/cms。  location / {           rewrite / /cms;     }

公司實戰nginx之rewrite配置域名

1.最近遇到了一個開發提的需求,訪問blog.cool360.org的時候跳轉到blog.cool360.org/blog的需求。 看著挺簡單的,但是還是研究了下才配置出來,主要還是不夠深入瞭解nginx的rewrite規則。 正確的配置如下: rewrite ^/$ htt

nginx泛解析域名實現多級域名多個域名

nginx 二級域名 需求如下:由於之前泛解析有上百個域名需要向上圖所示的這種需求,所以需要一個通用方法進行處理。思路如下:1,首先通過Nginx獲取到所有泛解析的二級子域名2,通過Nginx的 proxy_set_header 自定義變量獲取請求url主機頭部3,後端使用程序獲取Nginx傳遞過來的

Apache 域名配置

open none pro gpo inter val handler cli proxy 域名跳轉   就是實現URL的跳轉和隱藏真實地址,基於Perl語言的正則表達式規範。平時幫助我們實現擬靜態,擬目錄,域名跳轉,防止盜鏈等 。 參數格式 參數: Apache

Nginx網站常見的配置實例

apache 多個 referer double 404錯誤 主域名 log AC filename 相信大家在日常運維工作中如果你用到nginx作為前端反向代理服務器的話,你會對nginx的rewrite又愛又恨,愛它是因為你搞定了它,完成了開發人員的跳轉需求後你會覺得很

Apache(httpd)配置--用戶認證,域名和訪問日誌配置

用戶認證 域名跳轉 訪問日誌 一、用戶認證 用戶認證功能就是在用戶訪問網站的時候,需要輸入用戶名密碼才能進行訪問。一些比較好總要的站點和網站後臺都會加上用戶認證,以保證安全。實例:下面對zlinux.com站點來做一個全站的用戶認證: 步驟1:編輯虛擬主機配置文件 [root@zlinux ~]#

NGINX域名案列

IE erro isp sse clas cti default 是我 color 1、不同域名不同路徑跳轉 nginx實現a.com/teacher域名跳轉到b.com/student 若想實現上面題目的跳轉,目前鄙人知道兩種方式: 1.return 2.prox

nginx虛擬主機和域名

mpi pen inf 提示 etc 主機 表示 nginx.pid 父進程 nginx介紹 nginx官網 :nginx.orgnginx主要應用web服務、反向代理和負載均衡的作用上nginx分支,淘寶基於nginx開發的Tengine,使用上和nginx一致,服務和配

[備忘]Nginx 禁止IP訪問及未繫結的域名

轉載自: http://www.linuxidc.com/Linux/2011-04/34368.htm 今天要在Nginx上設定禁止通過IP訪問伺服器,只能通過域名訪問,這樣做是為了避免別人把未備案的域名解析到自己的伺服器IP而導致伺服器被斷網,從網路上搜到以下解決方案: Ngin

點選iframe框架的頁面出現欄目巢狀問題

今天在搭建一個全新後臺的時候,用的iframe框架巢狀的子頁面,當點選子iframe框架上的連結時候,出現了頁面巢狀混亂,如圖 這樣顯然格式是不正確的,百度了一下,只需要修改兩個屬性 (1)在標

nginx 域名一例~~~(rewrite、proxy)

前幾天搭了一個論壇伺服器並放到了公司的局域網裡面,論壇用的是9066埠並在路由器上面做了個埠轉發,而且把bbs.xxx.com這個域名也指向了公司的公網IP,因為想讓使用者在訪問的時候不用輸入埠號於是就想在公司的web伺服器上面做個跳轉,將訪問bbs.xxx.com的請求都轉

nginx 利用 proxy 反向代理解決 Ajax 跨域訪問,瀏覽器不顯示的連結

我們知道,利用nginx rewrite 可以重寫訪問連結,在後面加上last標籤就可以不在瀏覽器顯示跳轉後的連線。那麼如果要跨域跳轉呢? 如果還是使用rewrite,那麼nginx預設會重定向該連結。就算你後面加的last標籤也無濟於事,這樣瀏覽器就會顯示跳轉後的連結。Ajax開發中令人頭疼的問題

阿里雲一級域名https的二級域名配置說明(主域名轉子域名, 不帶www帶www)

阿里雲的免費域名證書目前不支援泛解析, 不支援萬用字元解析, 所有的證書只針對二級域名生效; 很多官網如果只對二級域名做配置https, 比如說, https://www.domain.com,  這種方式是可以正常跳轉, 但是使用者一般喜歡直接輸入 domain.com進行訪

linux安裝nginx域名,檔案下載,負載均衡(三)

參考連結::https://www.cnblogs.com/knowledgesea/p/5199046.html 一。跳轉檔案目錄 實現檔案下載 server { listen 80; server_name 域名; lo