Nginx reverse proxy springboot jar package source code analysis
样例一:
server { listen 80; server_name 127.0.0.1; access_log logs/book.log; error_log logs/book.error; #将/wx-service请求转发给http://127.0.0.1:8011/wx-service处理 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; } #将/bootdo请求转发给http://127.0.0.1:8012/bootdo处理 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; } #将/xcloud-service请求转发给http://127.0.0.1:8013/xcloud-api处理 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; } #将/eureka-service请求转发给http://127.0.0.1:8081/eureka-service处理 location /eureka-service { proxy_pass http://127.0.0.1:8081/eureka-service; #这里的端口记得改成项目对应的哦 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; } #将/xcloud-api请求转发给http://127.0.0.1:8082/xcloud-api处理 location /xcloud-api { proxy_pass http://127.0.0.1:8082/xcloud-api; #这里的端口记得改成项目对应的哦 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; } }
样例二:
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; } #将/wvv请求转发给http://127.0.0.1:1992/wvv处理 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; } }
如果是部署多个springboot项目,则可以多次添加如下配置,只要修改成不一样的路径即可
#将/wvv请求转发给http://127.0.0.1:1991/project处理
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; }
将nginx的端口改成80端口 域名就可以直接访问 service_name可以为localhost 代表本机 localtion /xxx这块就是配置nginx端口转发 不输了几个项目就配置几个 也可以将tomcat中的项目配置在这 也是没问题的 根据上述配置 在sbin目录执行 ./nginx -s reload 刷新nginx配置就会生效了
在这提供一个spring-boot快速重启shell脚本 亲测有效
export java_home=/usr/local/java/jdk1.8.0_162 export path=$java_home/bin:$path export classpath=.:$java_home/lib/dt.jar:$java_home/lib/tools.jar port=8081 jarname=clouddo-server.jar logspatch=./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 $logspatch mkdir $logspatch export.utf-8 set -m nohup java -jar -dlogging.path=$logspatch $jarname>$logspatch/catlina.out 2>&1 & tail -f $logspatch/catlina.out
保存命名为xx.sh
建议在nginx下建立一个单独的文件夹以项目名命名,然后将jar包放入其中,再启动jar包。
java -jar revenue-1.0.jar >revenue.txt &
记住 springboot项目得在配置文件中配置
server:
context-path: /xcloud-api
spring boot默认是/ 这样直接通过http://ip:port/就可以访问到index页面 但是我们要通过nginx配置多项目的话就要给每一个项目单独指定context-path
在服务器目录根据个人喜好新建一个文件夹 专门用来存放spring-boot打包成的jar 和重启脚本 类似这样
这样方便管理 logs目录是启动脚本之后生成的日志文件夹 忽略 一个项目对应一个文件夹 里面包含项目jar和一个重启shell脚本
这样就可以同时后台启动多个springboot项目并且通过一个域名来访问这些项目 如果要实时查看日志 请进入到每个项目文件的logs-目录执行
The above is the detailed content of Nginx reverse proxy springboot jar package source code analysis. For more information, please follow other related articles on the PHP Chinese website!

JVM implements the WORA features of Java through bytecode interpretation, platform-independent APIs and dynamic class loading: 1. Bytecode is interpreted as machine code to ensure cross-platform operation; 2. Standard API abstract operating system differences; 3. Classes are loaded dynamically at runtime to ensure consistency.

The latest version of Java effectively solves platform-specific problems through JVM optimization, standard library improvements and third-party library support. 1) JVM optimization, such as Java11's ZGC improves garbage collection performance. 2) Standard library improvements, such as Java9's module system reducing platform-related problems. 3) Third-party libraries provide platform-optimized versions, such as OpenCV.

The JVM's bytecode verification process includes four key steps: 1) Check whether the class file format complies with the specifications, 2) Verify the validity and correctness of the bytecode instructions, 3) Perform data flow analysis to ensure type safety, and 4) Balancing the thoroughness and performance of verification. Through these steps, the JVM ensures that only secure, correct bytecode is executed, thereby protecting the integrity and security of the program.

Java'splatformindependenceallowsapplicationstorunonanyoperatingsystemwithaJVM.1)Singlecodebase:writeandcompileonceforallplatforms.2)Easyupdates:updatebytecodeforsimultaneousdeployment.3)Testingefficiency:testononeplatformforuniversalbehavior.4)Scalab

Java's platform independence is continuously enhanced through technologies such as JVM, JIT compilation, standardization, generics, lambda expressions and ProjectPanama. Since the 1990s, Java has evolved from basic JVM to high-performance modern JVM, ensuring consistency and efficiency of code across different platforms.

How does Java alleviate platform-specific problems? Java implements platform-independent through JVM and standard libraries. 1) Use bytecode and JVM to abstract the operating system differences; 2) The standard library provides cross-platform APIs, such as Paths class processing file paths, and Charset class processing character encoding; 3) Use configuration files and multi-platform testing in actual projects for optimization and debugging.

Java'splatformindependenceenhancesmicroservicesarchitecturebyofferingdeploymentflexibility,consistency,scalability,andportability.1)DeploymentflexibilityallowsmicroservicestorunonanyplatformwithaJVM.2)Consistencyacrossservicessimplifiesdevelopmentand

GraalVM enhances Java's platform independence in three ways: 1. Cross-language interoperability, allowing Java to seamlessly interoperate with other languages; 2. Independent runtime environment, compile Java programs into local executable files through GraalVMNativeImage; 3. Performance optimization, Graal compiler generates efficient machine code to improve the performance and consistency of Java programs.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 English version
Recommended: Win version, supports code prompts!

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.
