最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

詳解nginx 代理多個服務(wù)器(多個server方式)

 更新時間:2017年10月16日 11:47:23   作者:0day__  
本篇文章主要介紹了詳解nginx 代理多個服務(wù)器(多個server方式),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

上一篇文章介紹了nginx的基本配置和使用方法,并且簡單的介紹了一下如何利用nginx結(jié)合tomcat進行使用,達到反向代理的作用。現(xiàn)在我們要使用nginx達到這樣的一個目的,能夠代理多個服務(wù)器。

首先修改配置文件:

#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 65; 
 
 #gzip on; 
 
 server { 
  listen  9922; 
  server_name firstProxyServer; 
 
  #charset koi8-r; 
 
  #access_log logs/host.access.log main; 
 
  #location / { 
   #root html; 
   #index index.html index.htm; 
  #} 
  location / { 
   proxy_pass http://localhost:8989; 
  } 
 
  #error_page 404    /404.html; 
 
  # redirect server error pages to the static page /50x.html 
  # 
  error_page 500 502 503 504 /50x.html; 
  location = /50x.html { 
   root html; 
  } 
 
  # proxy the PHP scripts to Apache listening on 127.0.0.1:80 
  # 
  #location ~ \.php$ { 
  # proxy_pass http://127.0.0.1; 
  #} 
 
  # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 
  # 
  #location ~ \.php$ { 
  # root   html; 
  # fastcgi_pass 127.0.0.1:9000; 
  # fastcgi_index index.php; 
  # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; 
  # include  fastcgi_params; 
  #} 
 
  # deny access to .htaccess files, if Apache's document root 
  # concurs with nginx's one 
  # 
  #location ~ /\.ht { 
  # deny all; 
  #} 
 } 
 
  server { 
  listen  9977; 
  server_name secondProxyServer; 
 
  #charset koi8-r; 
 
  #access_log logs/host.access.log main; 
 
  #location / { 
   #root html; 
   #index index.html index.htm; 
  #} 
  location / { 
   proxy_pass http://localhost:8080; 
  } 
 
  #error_page 404    /404.html; 
 
  # redirect server error pages to the static page /50x.html 
  # 
  error_page 500 502 503 504 /50x.html; 
  location = /50x.html { 
   root html; 
  } 
 
  # proxy the PHP scripts to Apache listening on 127.0.0.1:80 
  # 
  #location ~ \.php$ { 
  # proxy_pass http://127.0.0.1; 
  #} 
 
  # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 
  # 
  #location ~ \.php$ { 
  # root   html; 
  # fastcgi_pass 127.0.0.1:9000; 
  # fastcgi_index index.php; 
  # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; 
  # include  fastcgi_params; 
  #} 
 
  # deny access to .htaccess files, if Apache's document root 
  # concurs with nginx's one 
  # 
  #location ~ /\.ht { 
  # deny all; 
  #} 
 } 
 
 # another virtual host using mix of IP-, name-, and port-based configuration 
 # 
 #server { 
 # listen  8000; 
 # listen  somename:8080; 
 # server_name somename alias another.alias; 
 
 # location / { 
 #  root html; 
 #  index index.html index.htm; 
 # } 
 #} 
 
 
 # HTTPS server 
 # 
 #server { 
 # listen  443 ssl; 
 # server_name localhost; 
 
 # ssl_certificate  cert.pem; 
 # ssl_certificate_key cert.key; 
 
 # ssl_session_cache shared:SSL:1m; 
 # ssl_session_timeout 5m; 
 
 # ssl_ciphers HIGH:!aNULL:!MD5; 
 # ssl_prefer_server_ciphers on; 
 
 # location / { 
 #  root html; 
 #  index index.html index.htm; 
 # } 
 #} 
 
} 

其中主要的是有兩個server,每個server對應(yīng)的被代理的服務(wù)器的不同。從而實現(xiàn)了nginx代理多個服務(wù)器的目的。

下面是兩個服務(wù)server的配置:

server { 
  listen  9922; 
  server_name firstProxyServer; 
 
  #charset koi8-r; 
 
  #access_log logs/host.access.log main; 
 
  #location / { 
   #root html; 
   #index index.html index.htm; 
  #} 
  location / { 
   proxy_pass http://localhost:8989; 
  } 
 
  #error_page 404    /404.html; 
 
  # redirect server error pages to the static page /50x.html 
  # 
  error_page 500 502 503 504 /50x.html; 
  location = /50x.html { 
   root html; 
  } 
 
  # proxy the PHP scripts to Apache listening on 127.0.0.1:80 
  # 
  #location ~ \.php$ { 
  # proxy_pass http://127.0.0.1; 
  #} 
 
  # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 
  # 
  #location ~ \.php$ { 
  # root   html; 
  # fastcgi_pass 127.0.0.1:9000; 
  # fastcgi_index index.php; 
  # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; 
  # include  fastcgi_params; 
  #} 
 
  # deny access to .htaccess files, if Apache's document root 
  # concurs with nginx's one 
  # 
  #location ~ /\.ht { 
  # deny all; 
  #} 
 } 
 
  server { 
  listen  9977; 
  server_name secondProxyServer; 
 
  #charset koi8-r; 
 
  #access_log logs/host.access.log main; 
 
  #location / { 
   #root html; 
   #index index.html index.htm; 
  #} 
  location / { 
   proxy_pass http://localhost:8080; 
  } 
 
  #error_page 404    /404.html; 
 
  # redirect server error pages to the static page /50x.html 
  # 
  error_page 500 502 503 504 /50x.html; 
  location = /50x.html { 
   root html; 
  } 
 
  # proxy the PHP scripts to Apache listening on 127.0.0.1:80 
  # 
  #location ~ \.php$ { 
  # proxy_pass http://127.0.0.1; 
  #} 
 
  # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 
  # 
  #location ~ \.php$ { 
  # root   html; 
  # fastcgi_pass 127.0.0.1:9000; 
  # fastcgi_index index.php; 
  # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; 
  # include  fastcgi_params; 
  #} 
 
  # deny access to .htaccess files, if Apache's document root 
  # concurs with nginx's one 
  # 
  #location ~ /\.ht { 
  # deny all; 
  #} 
 } 

下面是測試的結(jié)果:

首先兩個tomcat中部署兩個服務(wù)器:


然后啟動nginx。

cmd下:start nginx

分別訪問這兩個server:

http://localhost:9922/ngtt/

http://localhost:9977/testnnnn/

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Nginx服務(wù)器配置HTTPS nginx.config 配置文件(教程)

    Nginx服務(wù)器配置HTTPS nginx.config 配置文件(教程)

    下面小編就為大家分享一篇Nginx服務(wù)器配置HTTPS nginx.config 配置文件(教程),具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2017-12-12
  • centos7下基于nginx+uwsgi部署Django項目的實現(xiàn)

    centos7下基于nginx+uwsgi部署Django項目的實現(xiàn)

    Django是一個開源的Web應(yīng)用框架,使用Python語言編寫,主要用于搭建Web項目,本教程介紹如何在centos7下基于nginx+uwsgi部署Django項目的實現(xiàn),感興趣的可以了解一下
    2024-04-04
  • 配置Nginx實現(xiàn)訪問本地靜態(tài)資源的完整指南

    配置Nginx實現(xiàn)訪問本地靜態(tài)資源的完整指南

    Nginx 是一個高性能的 HTTP 服務(wù)器和反向代理服務(wù)器,廣泛用于靜態(tài)資源的托管和負載均衡,在開發(fā)和生產(chǎn)環(huán)境中,我們常常需要使用 Nginx 來提供本地靜態(tài)資源的訪問,本文將詳細介紹如何配置 Nginx 以便訪問本地靜態(tài)資源,需要的朋友可以參考下
    2024-08-08
  • prometheus監(jiān)控nginx的實現(xiàn)

    prometheus監(jiān)控nginx的實現(xiàn)

    這篇文章主要介紹了prometheus監(jiān)控nginx的實現(xiàn),文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-03-03
  • Nginx服務(wù)器中的location配置詳解

    Nginx服務(wù)器中的location配置詳解

    這篇文章主要介紹了Nginx服務(wù)器中的location配置詳解,包括location的匹配順序等基本概念,需要的朋友可以參考下
    2015-08-08
  • Nginx下實現(xiàn)pathinfo及ThinkPHP的URL模式

    Nginx下實現(xiàn)pathinfo及ThinkPHP的URL模式

    本篇文章主要介紹了Nginx下實現(xiàn)pathinfo及ThinkPHP的URL模式。小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-05-05
  • Nginx if語句加正則表達式實現(xiàn)字符串截斷

    Nginx if語句加正則表達式實現(xiàn)字符串截斷

    這篇文章主要介紹了Nginx if語句加正則表達式實現(xiàn)字符串截斷功能,特殊場合下可能會需要這個功能,NGINX的奇淫技巧之一,需要的朋友可以參考下
    2015-02-02
  • nginx線程池源碼分析

    nginx線程池源碼分析

    雖然nginx的源碼非常精致,但是不得不說開發(fā)nginx很有挑戰(zhàn)性,越想更大程度上定制自己的模塊,越需要對nginx的每個細節(jié)了解頗深。
    2015-08-08
  • Nginx配置使用詳解

    Nginx配置使用詳解

    Nginx是一個高性能的HTTP和反向代理web服務(wù)器。本文詳細講解了Nginx配置使用的方法,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-06-06
  • Nginx 過濾靜態(tài)資源文件的訪問日志的實現(xiàn)

    Nginx 過濾靜態(tài)資源文件的訪問日志的實現(xiàn)

    這篇文章主要介紹了Nginx 過濾靜態(tài)資源文件的訪問日志的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-10-10

最新評論

朝阳区| 莆田市| 天峻县| 石柱| 阿城市| 廊坊市| 宁安市| 大余县| 含山县| 舟山市| 武义县| 介休市| 柳河县| 滦南县| 扎囊县| 兴宁市| 汝城县| 辽中县| 黎平县| 平乐县| 五原县| 禄丰县| 蚌埠市| 屏东市| 江口县| 宁阳县| 吉林省| 仁布县| 荣成市| 白河县| 临颍县| 依安县| 马尔康县| 舒兰市| 花莲市| 临汾市| 美姑县| 宜兴市| 仙桃市| 库车县| 巩义市|