nginx 代理 springboot 项目

注:centos7 服务器一台,可用域名一个,springboot web应用一套

下面来描述一下nginx+springboot+centos7 如何部署吧:

1.应用编写(本项目使用springboot编写)注意项目的application.yml(property配置为server.context-path=/yyy/)的配置文件添加如下配置


server: port: xxx context-path: /yyy/

上面的 xxx 为项目端口 ,yyy 为项目名称或者为项目起一个特定的标识(一串字符就可以,但必须以斜杠开始,否则会报错,小编已近采坑)

2.安装 nginx 参考 https://blog.csdn.net/oldguncm/article/details/78855000 当然也可以参考其他博客,网上有很多的

3.有一个可用的域名(没有就去买一个,很便宜的)

4.配置nginx

修改配置文件 /etc/nginx/nginx.conf(此处的yyy和第一步的yyy必须对应,不然静态资源会因为路径错误出现404)


server { listen 80 default_server; server_name my.com; # Load configuration files for the default server block. # include /etc/nginx/default.d/*.conf; location /yyy/ { # 项目一 proxy_pass http://104.12.1.3:xxx/yyy/; # 项目1对应的ip和端口 proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } error_page 404 /404.html; location = /40x.html { }}

5.重启nginx

systemctl restartstart nginx 也可以 service nginx restart

6.启动你的springboot 项目

照例附上美图!更多精彩内容请关注百战程序员!另外,求关注呐求收藏呐!

7.访问 http:www.my.com/yyy/login 此处的login为你的项目访问入口,也可以为其他的路径