Nginx configuration 80 port access 8080 and project name address method analysis
- 2021-09-05 01:19:12
- OfStack
tomcat access project, 1 is generally ip + port + project name
nginx configuration location/{}, 1 can only jump to ip + port, if you want to access the project directly, you need to modify the configuration of tomcat
How to ensure that the configuration of tomcat is not modified, only nginx is modified, and the port + project name can be accessed
After trying, I found one way, that is, through
location / {
proxy_pass http://127.0. 0.1: 8080/demo;
}
Jump to
location /demo {
proxy_pass http://127.0. 0.1: 8080;
}
demo is the project name, which is the file name configured under webapps of tomcat
Only this configuration will show the project name in the url address, but what is the so-called
Here is a configuration example:
upstream tomcatproject{
ip_hash;
server 11.1.11.11:8080;
server 22.2.22.22:8080;
}
server {
listen 80;
#server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://tomcatproject/demo;
}
location /demo/ {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://tomcatproject;
}
}