反向代理配置成功
首先,Nginx 和 Java 后端都運行在云服務器的 docker 容器中,ps: 需要確保云服務器埠正常開放,以及兩個容器都能被正常的訪問,
現在想讓 ng 做反向代理達到如下目的:通過前端 url 地址的映射,來訪問后端的介面,
反向代理流程:前端 url 地址 =》ng服務器 =》 后端服務器,
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
server {
listen 82; # 監聽的埠
server_name localhost; # 域名或ip
location / { # 訪問路徑配置
root /usr/share/nginx/html/regist/;# 根目錄
index index.html; # 默認首頁
}
# 配置如上,通過 localhost:82 的方式就可以訪問到 index.html
# 如下是配置反向代理,瀏覽器通過訪問 http://云服務器ip:82/reg/
# 就可以訪問到后端http://云服務器ip:8800/
location /reg/ {
proxy_pass http://云服務器ip:8800/;
}
error_page 500 502 503 504 /50x.html; # 錯誤頁面
location = /50x.html {
root html;
}
}
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on; 111
include /etc/nginx/conf.d/*.conf;
}
注意
反向代理的配置規則:
反向代理的映射:
http://ip:82/reg/ 對應到 http://云服務器ip:8800/
反向代理的配置規則:
其中的每個斜桿必不可少,否則會匹配不到,
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/554437.html
標籤:其他
下一篇:返回列表
