麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 網站 > Nginx > 正文

nginx+tomcat單個域名及多個域名配置教程

2024-08-30 12:29:17
字體:
來源:轉載
供稿:網友

項目開發接近尾聲,開始著手在生產環境部署項目,開發階段部署項目都沒用nginx。項目是采用SOA架構,多系統開發,主要包括服務系統、中臺系統、后臺系統、金融系統、接口系統、調度系統、報表系統等。這類分布式的系統,一般也都會用到nginx來做負載均衡。

從公司剛成立就進來,趕鴨子上架來做架構師,負責公司的所有研發事情,搭建公司的整個技術架構,起初的所有核心業務代碼基本都由自己親自把關來進行編碼。系統也從最初的只有一個pc端,發展到如今pc中臺、后臺、android端3個app、iOS端3個app,產品越做越多,親自負責招聘面試、培訓。之前很多時候都有過無助和苦惱,因為負責公司整個架構,又要負責核心業務的編碼,技術難點的攻克,新員工的招聘及培訓,現在團隊已經都發展到16個人,而且這全是研發人員。

回想這一路,覺得之前看似爬不過去的山也不過如此,也許這就是成長吧,成長總是會伴隨些許汗水與淚水吧。由于是負責團隊的所有事情,所以數據庫的維護、遷移數據、建索引等性能優化,項目部署等所有事情必須得一肩挑,不要問我為什么公司沒有DBA?為什么沒有運維?我真的只能給你一個眼神,讓你慢慢去體會。

話不多說,直接開始技術干貨分享。

nginx做負載均衡的優勢網上有很多介紹資料,這里我不再多做介紹。因為有很多系統要部署,涉及到域名、二級域名、多個域名等的部署。在實際的部署由于對nginx的不夠熟悉,遇到過很多坑,其中這種多域名的配置,xxxx.com轉發到www.xxxx.com、訪問域名轉發到tomcat里的項目等,現在先總結一部坑的解決辦法。

如將xxxx.com這個域名指向8082端口里的tomcat項目,在做這個介紹前先講個插曲,如訪問xxxx.com需轉向到www.xxxx.com,這一點很多人都會忽略。

現在如果要部署中臺、后臺、金融系統,找到nginx/conf/nginx.conf,修改配置:

upstream web{  server localhost:8082;}upstream admin{  server localhost:8083;}upstream finance{  server localhost:8084;}server {  listen    80;  server_name finance.xxxx.com;  #charset koi8-r;  #access_log logs/host.access.log main;  location / {    proxy_pass http://finance;    proxy_set_header Host $http_host;    proxy_set_header X-Real-IP $remote_addr;    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;  }  #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;  }}server {  listen    80;  server_name www.xxx.com;  #charset koi8-r;  #access_log logs/host.access.log main;  location / {    proxy_pass http://web;    proxy_set_header Host $http_host;    proxy_set_header X-Real-IP $remote_addr;    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;        }  #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 {  server_name xxxx.com;  rewrite ^(.*) http://www.xxxx.com$1 permanent;}server {  listen    80;  server_name admin.xxxx.com;  #charset koi8-r;  #access_log logs/host.access.log main;  location / {    proxy_pass http://admin;    proxy_set_header Host $http_host;    proxy_set_header X-Real-IP $remote_addr;    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;        }  #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;  #}}

 上面的配置還包括了訪問xxxx.com轉向www.xxxx.com的配置,如下:

server {   server_name xxxx.com;   rewrite ^(.*) http://www.xxxx.com$1 permanent; }

nginx的基本配置大致就是這樣,如果綁定多個域名(不管是一級域名還是二級域名),需配置多個server,你會發現這幾個server配置都差不多,主要是更改server_name及proxy_pass指向即可。upstream節點其實就是代理服務的訪問路徑。

如果此時訪問域名,你會發現nginx的配置生效了,只是目前顯示的是tomcat的默認界面。nginx的配置基本就這樣了,接下來對tomcat做些配置的修改。找到tomcat里的conf/server.xml,注釋掉默認的Host配置,添加如下Host配置:

<Host name="localhost" appBase="E:/tomcat/apache-tomcat-8.0.35-8082/webapps/web" deployOnStartup ="false" autoDeploy="false" unpackWARs="true">       <Context path="/" docBase="E:/tomcat/apache-tomcat-8.0.35-8082/webapps/web" />       <Valve  className="org.apache.catalina.valves.AccessLogValve"        directory="logs"   prefix="localhost_access_log"  suffix=".txt"        pattern="%h %l %u %t "%r" %s %b"  /></Host>

以上是windows服務器下的配置,如為linux,只需更改appBase和docBase,指向項目的路徑。tomcat的配置也已經完成,重啟tomcat,訪問域名就指向了tomcat里的項目。

總結

以上所述是小編給大家介紹的nginx+tomcat單個域名及多個域名配置,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對VEVB武林網網站的支持!


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 4p嗯啊巨肉寝室调教男男视频 | 国产精品视频六区 | 中文字幕欧美亚洲 | 特级毛片免费 | 精品中文视频 | 日韩精品羞羞答答 | 激情亚洲一区二区三区 | 久久色在线 | 女女久久 | 一级做a爱片性色毛片 | 日本中文字幕网址 | 奶子吧naiziba.cc免费午夜片在线观看 | 在线亚洲观看 | 超级av在线 | 亚洲一区成人 | 久久影院一区二区三区 | 精精国产xxxx视频在线播放7 | 深夜福利久久久 | 爽爽淫人综合网网站 | 曰韩黄色片 | 一级在线视频 | 97zyz成人免费视频 | 国产成人视屏 | 久久精品视频8 | 亚洲成人自拍电影 | 99re66热这里只有精品8 | 午夜av男人的天堂 | 久久久毛片视频 | 把娇妻调教成暴露狂 | 欧美亚洲综合在线 | 国产一区视频在线免费观看 | 少妇一级淫片免费放正片 | 国产91丝袜在线播放 | 亚洲特黄 | chinese-xvideos| 国产精品入口夜色视频大尺度 | 日本在线视频免费观看 | 久久久国产精品免费观看 | 99精品视频在线导航 | 国产精品视频yy9299一区 | 九九热视频在线免费观看 |