nginx 代理 springboot 項目

注:centos7 服務器一臺,可用域名一個,springboot web應用一套

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

1.應用編寫(本項目使用springboot編寫)注意項目的application.yml(property配置為server.context-path=/yyy/)的配置文件添加如下配置


  1. server:
  2. port: xxx
  3. 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)


  1. server {
  2. listen 80 default_server;
  3. server_name my.com;
  4. # Load configuration files for the default server block.
  5. # include /etc/nginx/default.d/*.conf;
  6. location /yyy/ { # 項目一
  7. proxy_pass http://104.12.1.3:xxx/yyy/; # 項目1對應的ip和端口
  8. proxy_set_header Host $host;
  9. proxy_set_header X-Real-IP $remote_addr;
  10. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  11. }
  12. error_page 404 /404.html;
  13. location = /40x.html {
  14. }
  15. }

5.重啟nginx

systemctl restartstart nginx 也可以 service nginx restart

6.啟動你的springboot 項目

nginx 代理 springboot 項目

照例附上美圖!更多精彩內容請關注百戰程序員!另外,求關注吶求收藏吶!

7.訪問 http:www.my.com/yyy/login 此處的login為你的項目訪問入口,也可以為其他的路徑


分享到:


相關文章: