Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Analysis of jar packet Source Code of Nginx reverse proxy springboot

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the knowledge of "jar package source code analysis of Nginx reverse proxy springboot". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Example 1:

Server {listen 80; server_name 127.0.0.1; access_log logs/book.log; error_log logs/book.error; # forwards / wx-service request to http://127.0.0.1:8011/wx-service processing location / wx-service {proxy_set_header host $host; proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for Proxy_pass http://127.0.0.1:8011/wx-service;} # forward / bootdo request to http://127.0.0.1:8012/bootdo processing location / bootdo {proxy_set_header host $host; proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for; proxy_pass http://127.0.0.1:8012/bootdo; } # forward / xcloud-service request to http://127.0.0.1:8013/xcloud-api processing location / xcloud-service {proxy_set_header host $host; proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for; proxy_pass http://127.0.0.1:8013/xcloud-api; } # forward / eureka-service request to http://127.0.0.1:8081/eureka-service processing location / eureka-service {proxy_pass http://127.0.0.1:8081/eureka-service; # remember to change the port here to the project corresponding to oh proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for; proxy_set_header x-forwarded-proto $scheme Proxy_set_header x-forwarded-port $server_port;} # forward / xcloud-api request to http://127.0.0.1:8082/xcloud-api processing location / xcloud-api {proxy_pass http://127.0.0.1:8082/xcloud-api; # remember to change the port here to the project corresponding to oh proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for Proxy_set_header x-forwarded-proto $scheme; proxy_set_header x-forwarded-port $server_port;}}

Example 2:

Server {listen 80; server_name localhost; # charset koi8-r; # access_log logs/host.access.log main; location / {root html; index index.html index.htm index.php;} # forward / wvv request to http://127.0.0.1:1992/wvv processing location / wvv {proxy_set_header host $host Proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for; proxy_pass http://127.0.0.1:1992/wvv;}}

If you are deploying multiple springboot projects, you can add the following configuration multiple times, as long as you change it to a different path

# forward / wvv request to http://127.0.0.1:1991/project for processing

Location / project {proxy_set_header host $host; proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for; proxy_pass http://127.0.0.1:1991/project;}

If you change the port of nginx to an 80-port domain name, you can directly access service_name and represent native localtion / xxx for localhost. This is to configure nginx port forwarding. If you do not lose a few items, you can also configure several items in tomcat. According to the above configuration, you can also configure items in the sbin directory. / nginx-s reload refresh nginx configuration will take effect.

Provide a spring-boot quick restart shell script here to test it effectively

Export java_home=/usr/local/java/jdk1.8.0_162export path=$java_home/bin:$pathexport classpath=.:$java_home/lib/dt.jar:$java_home/lib/tools.jar port=8081jarname=clouddo-server.jarlogspatch=./logs_$port id= `ps-ef | grep $port | grep-v "grep" | awk'{print $2} '`echo $id echo "-" for id in $id do kill-s 9$ id echo "killed $id" done echo " -"rm-rf $logspatchmkdir $logspatch export.utf-8 set-m nohup java-jar-dlogging.path=$logspatch $jarname > $logspatch/catlina.out 2 > & 1 & tail-f $logspatch/catlina.out

Save and name it xx.sh

It is recommended that you set up a separate folder under nginx named after the project name, then put the jar package into it, and then start the jar package.

Java-jar revenue-1.0.jar > revenue.txt &

Remember that the springboot project has to be configured in the configuration file

Server:

Context-path: / xcloud-api

Spring boot defaults to / so that the index page can be accessed directly through http://ip:port/, but if we want to configure multiple projects through nginx, we have to specify a separate context-path for each project.

Create a new folder in the server directory according to your preferences to store jar packaged by spring-boot and restart scripts like this

This makes it easy to manage the logs directory. The log folder generated after starting the script ignores a project corresponding to a folder that contains the project jar and a restart shell script.

In this way, multiple springboot projects can be started in the background at the same time and accessed through a domain name. If you want to view logs in real time, go to the logs- directory of each project file for execution.

This is the end of the content of "jar package source code analysis of Nginx reverse proxy springboot". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report