且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Nginx的简单反向代理(等效于Apache)

更新时间:2023-09-18 23:40:40

您的配置看起来很接近.

Your configuration looks close.

  • 代理头应该没问题.通常Nginx会通过标头,因此当您要修改标头时会使用proxy_set_header-例如,即使客户端不提供标头,也要强制显示Host标头.

  • Proxy headers should be fine. Normally Nginx passes headers through, so proxy_set_header is used when you want to modify those - for example forcing the Host header to be present even if the client does not provide one.

对于proxy_pass和上游,是的,名称需要匹配.

For the proxy_pass and upstream, yes the names need to match.

请考虑将proxy_redirect保留为打开状态(默认).此选项可修改Nginx是否干扰诸如301& amp;的响应.302重定向,包括端口号.关闭它意味着您的upsteam应用程序必须负责在任何重定向响应中传递正确的公共域名和端口.将其保留为默认值意味着,如果您不小心尝试将客户端定向到端口8080,则在某些情况下Nginx会将其更正为端口80.

Consider leaving proxy_redirect on (default). This option modifies whether Nginx interferes with responses like 301 & 302 redirects including the port number. Turning it off means that your upsteam application must take responsibility for passing the correct public domain name and port in any redirect responses. Leaving it set to default means that if you accidentally try to direct the client to port 8080, Nginx would in some cases correct it to be port 80 instead.

您还没有在nginx配置中包含/excluded路径.将其添加到

You also did not include the /excluded path in your nginx config. Add that in with

location /excluded {
    return 403;
}