tomcat的server.xml文件下可以配置<Context path > docBase 配置项目的访问路径,这样可以直接访问tomcat的端口不用加项目名称来访问项目。
<Context path="" docBase="/usr/project/XYD" reloadable="true">
</Context>
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<Context path="" docBase="/usr/project/XYD" reloadable="true">
</Context>
<!-- 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 -->
<!--
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/>
-->
</Host>
nginx proxy_pass实现项目upstream负载:
upstream hostname{
server 127.0.0.1:8080 max_fails=0 weight=1;
server 127.0.0.1:8090 max_fails=0 weight=1;
server 192.168.5.82:8080 max_fails=0 weight=1;
}
server {
listen 80;
server_name _;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_pass http://hostname;
proxy_set_header X-Real-IP $remote_addr;
#root /usr/share/nginx/html;
#index index.html index.htm;
# example
#ModSecurityEnabled on;
#ModSecurityConfig /etc/nginx/modsecurity.conf;
#rewrite ^/ http://192.168.5.31:8080/XYD;
}
error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
}
----rewrite的解释
#rewrite ^/ http://192.168.5.31:8080/XYD; 配置后 访问 localhost后项目直接跳转到相应的域名项目目录。