当前位置:首页 > nginx > 正文

nginx二级域名转发(nginx一个域名配置多个网站)

  • nginx
  • 2024-04-03 07:56:29
  • 1352
Nginx 二级域名转发
使用 Nginx 将请求转发到二级域名的过程。 它允许您将特定 URL 路径上的请求重定向到不同的服务器或应用程序。
要素:

1. 服务器块
定义要转发的域名。
例如:
server {
server_name example.com;
}

2. location 块
指定要转发的 URL 路径。
例如:
location /subdomain {
# ...
}

3. proxy_pass 指令
指定转发请求的目标服务器或应用程序。
例如:
proxy_pass http://subdomain.example.com;

4. proxy_set_header 指令
设置要发送到目标服务器的请求头。
例如:
proxy_set_header Host subdomain.example.com;

5. proxy_redirect 指令
配置 Nginx 在重定向时保留原始请求的 URI。
例如:
proxy_redirect off;