如何提取子域并将其作为Node.js和Haproxy中的参数传递 [英] How to extract subdomain and pass it as a parameter in Node.js and Haproxy
本文介绍了如何提取子域并将其作为Node.js和Haproxy中的参数传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,
我已将我的专用服务器配置为使用默认端口(80)将域名链接到我的nodejs端口。例如。 site1.com到端口2222和site2.com到端口3333.
我的问题是如何传递子域名作为参数,例如:
param1.site1.com:80应该转到127.0.0.1:2222/param1
我的haproxy配置:
Hello,
I have configured my dedicated server to link domains with default port (80) to my nodejs ports accordingly to domain name. E.g. site1.com to port 2222 and site2.com to port 3333.
My question is how to pass a subdomain name as a parameter, e.g.:
param1.site1.com:80 should go to 127.0.0.1:2222/param1
My haproxy config:
global
log 127.0.0.1 local0
log 127.0.0.1 local1 notice
maxconn 4096
user haproxy
group haproxy
daemon
defaults
log global
mode http
option httplog
option dontlognull
retries 3
option redispatch
maxconn 2000
contimeout 5000
clitimeout 50000
srvtimeout 50000
frontend http-in
bind *:80
acl is_www_site1_com hdr_end(host) -i site1.com
acl is_www_site2_com hdr_end(host) -i site2.com
use_backend www_site1_com if is_www_site1_com
use_backend www_site2_com if is_www_site2_com
default_backend www_site1_com
backend www_site1_com
balance roundrobin
cookie SERVERID insert nocache indirect
option httpchk HEAD /check.txt HTTP/1.0
option httpclose
option forwardfor
server Server1 127.0.0.1:2222 cookie Server1
backend www_site2_com
balance roundrobin
cookie SERVERID insert nocache indirect
option httpchk HEAD /check.txt HTTP/1.0
option httpclose
option forwardfor
server Server1 127.0.0.1:3333 cookie Server1
我希望有人知道回答:)谢谢!
I hope someone knows answer :) Thanks!
推荐答案
如果haproxy将站点重定向到特定的服务器和端口,主机名仍应保持不变用户浏览器,以便您应该能够从主机名中提取子域,然后在站点上重定向到与子域相关的特定文件夹,如Apache的RewriteEngine或使用php或Node.js modu le服务器本身??
If haproxy redirects the site to the specific server and port, the host name should still stay the same in the users browser so you should be able to extract the subdomain from the hostname and then redirect on the site to the specific folder relating to the subdomain such as Apache's RewriteEngine or using a php or Node.js module on the server itself??
这篇关于如何提取子域并将其作为Node.js和Haproxy中的参数传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文