In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "how to achieve nginx+tomcat reverse proxy and dynamic separation", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "how to achieve nginx+tomcat reverse proxy and static separation" bar!
1. Install nginx and access static resources
After the installation is successful, start nginx and enter http://localhost/ in the browser to display the welcome page.
Create the directory static\ test1\ js\ common under nginx, and put jquery.xx.js in it.
Ps: static represents the home directory of static files, test1 represents the project name under tomcat, and jquery-1.12.1.min.js is used locally.
Modify the configuration file nginx.conf to add the following configuration:
# regular matches requests that start with static, such as / test1/static/js...
Location ^ ~ / test1/static/ {
Alias static/test1/; # alias discards the path configured after location; when using alias, the directory name must be followed by /
}
Restart nginx and enter http://localhost/test1/static/js/common/jquery-1.12.1.min.js in the browser to access it successfully.
two。 Build a java web project
Install jdk,tomcat,myeclipse or idea, etc., and create web project test1.
Set the test1 welcome page to index.jsp and deploy it under tomcat with port number 8080
The browser can access it successfully by entering http://localhost:8080/test1/.
3. Introduce static resources under nginx
Introduce the jquery file of nginx under index.jsp:
Src= "http://localhost/test1/static/js/common/jquery-1.12.1.min.js"
At the same time, write the jquery test script as follows:
/ / jquery syntax. Successful alert indicates that jquery was introduced successfully $(function () {alert ("Test movement separation succeeded!") ;})
Configure the reverse proxy for the test1 project under nginx, modify the nginx.conf, and add the following configuration:
# test1 project request-- > reverse proxy to 8080, except for ^ ~ / test1/static/ request
Location / test1/ {
Proxy_pass http://localhost:8080;
}
4. Test reverse proxy and static and dynamic separation
Restart nginx, restart tomcat!
Enter http://localhost/test1/ in the browser, and the request will be forwarded by nginx to test1 under tomcat on port 8080.
If everything is ok, the browser will return the output of index.jsp and load the jquery file under nginx, popping up a prompt box.
Screenshot of this machine:
Thank you for your reading, the above is the content of "how to achieve nginx+tomcat reverse proxy and static and dynamic separation". After the study of this article, I believe you have a deeper understanding of how to achieve the reverse proxy and static separation of nginx+tomcat, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.