nginx配置代理
nginx中server块中,listen 80 跟外部web浏览器访问的端口没有关系,比如外部是30000端口,一样可以把访问放入nginx,其中的匹配优先级是:如果listen中写了IP和端口,会先匹配相应的IP,再匹配server_name中的域名,如果匹配,就把请求丢给对应的location来处理。
server {
listen 80;
listen [::]:80;
server_name frontvue-xxx.com;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
location /auth {
proxy_pass http://xxx.com:30000;
}
location /api-apm {
proxy_pass http://abcxxx.com:30000;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
proxy_pass有/,实际访问地址(代理后的url)就没有location的地址,proxy_pass没有/(上面的请求就没有 / ),实际访问地址就会带上location 的部分
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构