前些天發現了一個巨牛的人工智能學習網站,通俗易懂,風趣幽默,忍不住分享一下給大家。點擊跳轉到教程。
1.需求:直接域名訪問項目,不用IP,也不帶端口號。
1)訪問項目方法通常是 IP:端口,不想帶端口時可把這個工程部署在80端口上,這樣可以默認80,URL上不用寫端口號。
?
2.? 不用把前端工程部署在80端口上。
1)把前端工程部署在3000端口上,后端工程部署在8089上,由 nginx 監聽 80 端口并作代理。
2)nginx.conf 配置:
server {listen 80;server_name ergouzi.fun; # 域名或者服務器IPlocation / {root /usr/local/dist; # vue項目dist所在路徑index index.html index.htm;}location /gentle/ { # gentle 是后端工程名,可區分不同后端工程 proxy_pass http://localhost:8089; # 后端工程請求地址 }location /dagouzi/ { # dagouzi 是另一后端工程 proxy_pass http://localhost:8088; proxy_set_header X-real-ip $remote_addr; proxy_set_header Host $http_host;}error_page 500 502 503 504 /50x.html;location = /50x.html {root html;}}
這樣,服務器根本不用對外開放 3000、8089、8088 這些端口。
?
瀏覽器上直接訪問 server_name 中配置內容就可以了。比如,我這就是直接訪問 :ergouzi.fun。
(PS:ergouzi.fun 我這個域名還未備案通過,目前尚只能訪問對應IP。)
?
補充:前端請求后端接口方式為:
?
?
?
?
?