NGINX+haproxy 怎么配置域名
时间: 2023-12-15 10:04:21 浏览: 157
首先,你需要在DNS服务器上设置相应的域名解析记录,将域名指向你的服务器IP地址。
然后,在NGINX和HAProxy中配置相应的虚拟主机。以下是具体步骤:
1. 在NGINX中,打开nginx.conf文件,将以下代码添加到http块中:
```
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://your_upstream_server;
}
}
```
其中,example.com为你要绑定的域名,your_upstream_server为你的upstream服务器地址。如果你想使用HTTPS协议,则需要添加SSL配置。
2. 在HAProxy中,打开haproxy.cfg文件,将以下代码添加到frontend块中:
```
frontend http-in
bind *:80
acl host_example_com hdr(host) -i example.com
use_backend example_com if host_example_com
backend example_com
server your_backend_server your_upstream_server:80
```
其中,example.com为你要绑定的域名,your_backend_server为你的后端服务器地址,your_upstream_server为你的upstream服务器地址。同样,如果你想使用HTTPS协议,则需要添加SSL配置。
配置完成后,重启NGINX和HAProxy服务即可生效。
阅读全文
相关推荐
















