2019-01-23

Nginx+Tomcat單個域名加多個域名配置

現(xiàn)在如果要部署中臺、后臺、金融系統(tǒng),找到nginx/conf/nginx.conf,修改配置:


upstream web{

? ? server localhost:8082;

}

upstream admin{

? ? server localhost:8083;

}

? ? server {

listen? ? ? 80;

server_name? wap.mzjicai.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;

}

}

server {

listen? ? ? 80;

server_name? www.mzjicai.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;

#}

}

server {

server_name xxxx.com;

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

}

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

server {

?????server_name xxxx.com;

?????rewrite ^(.*) http://www.xxxx.com$1 permanent;

?}

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

如果此時訪問域名,你會發(fā)現(xiàn)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里的項目。

?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容