http {
2 ......
3 server {
4 listen 80;
5 server_name test.assad.site; #原始請求URL
6
7 location / { #轉發所有請求給Tomcat
8 proxy_pass http://127.0.0.1:8080/testapp; #轉發給Tomcat的uri路由
9 proxy_set_header Host $http_addr;
10 proxy_set_header X-Real-IP $remote_addr;
11 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
12 }
13 }
14}
<Host name="test.assad.site" appBase="/tomcat/webapps/testapp" unpackWARs="true" autoDeploy="true">
2 <Context path="" docBase="/tomcat/webapps/testapp" debug="0" reloadable="true" />
3 <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
4 prefix="localhost_access_log." suffix=".txt"
5 pattern="%h %l %u %t "%r" %s %b" />
6</Host>
7
其中name字段為請求URL,appBase字段為該URL轉發到的 web application 的更目錄;http{
2 ......
3 include vhost/*.conf;
4}
在 /nginx/conf/vhost 下創建“test1.assad.site.conf”"test2.assad.site.conf" 兩個文件,以"test1.assad.site.conf"的配置示例,內容如下:upstream testapp1 { #設置一個upstream
2 server 127.0.0.1:8080;
3}
4server {
5 listen 80; #監聽的系統端口
6 server_name test1.assad.site; #代理轉發的原始URL
7 charset utf-8; #字符編碼
8
9 root /tomcat/webapps/testapp1; # 相應webapp的根目錄
10 index index.html index.htm index.jsp #起始頁
11
12 error_page 404 /errpage/404.html; # http錯誤頁路徑
13 error_page 500 502 503 504 /errpage/50x.html;
14
15 location / { #轉發所有的請求
16 proxy_pass http://testapp1; #代理轉發的upstream,格式http://upstream_name
17 proxy_set_header Host $http_host;
18 proxy_set_header X-Real-IP $remote_addr;
19 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
20
21 }
22}
test2.assad.site.conf 配置類似以上....
2<Host name="test1.assad.site" appBase="/tomcat/webapps/testapp1" unpackWARs="true" autoDeploy="true">
3 <Context path="" docBase="/tomcat/webapps/testapp1" debug="0" reloadable="true" />
4 <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
5 prefix="localhost_access_log." suffix=".txt"
6 pattern="%h %l %u %t "%r" %s %b" />
7</Host>
8<Host name="test2.assad.site" appBase="/tomcat/webapps/testapp2" unpackWARs="true" autoDeploy="true">
9 <Context path="" docBase="/tomcat/webapps/testapp2" debug="0" reloadable="true" />
10 <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
11 prefix="localhost_access_log." suffix=".txt"
12 pattern="%h %l %u %t "%r" %s %b" />
13</Host>
14....
本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。