centos7.9 配置nginx實現前後端分離
工作中經常會遇到需要部署前後端分離的專案,今天來給大家介紹一下。 |
實驗目的:
實現前後端分離配置,即nginx做代理,前端需要跳轉到本地目錄訪問,後端需要跳轉到後端程式。
伺服器:
release 7.9.2009 (Core)
nginx版本:nginx-1.14.2
部署nginx
上傳部署包
[[email protected] tools]# ls nginx-1.14.2.tar.gz
[[email protected] tools]# tar xf nginx-1.14.2.tar.gz
[[email protected] tools]# cd nginx-1.14.2
[[email protected] nginx-1.14.2]# ./configure
[[email protected] nginx-1.14.2]# make
[[email protected] nginx-1.14.2]# make install
配置前端訪問目錄
配置nginx配置檔案nginx.conf,擷取到/jingtai/就會跳轉到/opt/jingtai/路徑
... location ^~/jingtai/ { alias /opt/jingtai/; index index.html index.htm; ...
配置後端訪問
在配置檔案新增一個server
server { listen 8090; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location ^~/dongtai/ { alias /opt/dongtai/; index index.html index.htm; } }
在原server新增
upstream dongtai{ server 127.0.0.1:8090; } server { listen 9090; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; #jingtai location ^~/jingtai/ { alias /opt/jingtai/; index index.html index.htm; } #dongtai location ^~/dongtai/ { proxy_pass }
驗證
9090埠代表代理服務和本地前端服務
8090埠代表後端服務
當9090攔截/dongtai/時匹配的是8090埠的路徑.
當9090攔截/jingtai/時匹配的是9090/opt/jingtai/的路徑。
[[email protected] opt]# curl 127.0.0.1:9090/dongtai/ dongtai [[email protected] opt]# curl 127.0.0.1:9090/jingtai/ jingtai [[email protected] opt]#
結束
這就是前後端分離的流程
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/31524109/viewspace-2853710/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 一份簡單夠用的 Nginx Location 配置講解
- ubuntu20 原始碼安裝nginx以及常用命令
- Hexo部落格部署到騰訊雲伺服器全過程(Nginx,證書,HTTPS),你要的這裡都有
- Nginx 全模組安裝及匹配方式、反向代理和負載均衡配置
- 寶塔 Centos7.x安裝pdo_sqlsrv 擴充套件
- Nginx 基礎入門
- Nginx 和 Gunicorn 效能對比測試
- 製作JavaCV應用依賴的基礎Docker映象(CentOS7+JDK8+OpenCV4)
- centos7關閉防火牆命令 centos7永久防火牆關閉
- 使用docker-compsoe構建一個簡單nginx+php環境
- Nginx 反向代理解決跨域問題分析
- docker初體驗:docker部署nginx服務
- 神器 Nginx 的學習手冊 ( 建議收藏 )
- NGINX創始人Igor離職
- 虛擬化架構與Centos7系統部署
- Nginx 動態模組 nginx-mod-http-image-filter 載入失敗解決