Nginx+Tomcat实现反向代理
域名访问通过nginx转tomcat不带项目名配置方法:
1.配置tomcat修改server.xml,在Host最后处添加context访问路径为 "/",如下:
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"> <!-- SingleSignOn valve, share authentication between web applications Documentation at: /docs/config/valve.html --> <!-- <Valve className="org.apache.catalina.authenticator.SingleSignOn" /> --> <!-- Access log processes all example. Documentation at: /docs/config/valve.html Note: The pattern used is equivalent to using pattern="common" --> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log" suffix=".txt" pattern="%h %l %u %t "%r" %s %b" /> <Context path="/" docBase="/usr/local/tomcat/webapps/sms/" debug = "0" reloadable="true" crossContext="true" /> </Host>
2.修改nginx,如下配置:
server { listen 80; server_name sms.baidu.com; --设置域名 #charset koi8-r; #access_log /var/log/nginx/host.access.log main; location / { proxy_pass http://172.16.3.187:30001; #proxy_redirect http://172.16.3.187:30001/ams/ /; 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 /usr/share/nginx/html; } }