Nginx 多域到一台服务器配置
我的服务器中有 1 个应用程序。
www.mainsite.com/adminindex
www.mainsite.com/landingpage
我希望多个域能够打开此应用程序并且仍然使用 Nginx 屏蔽/代理域 URL。但无论我做了什么配置,它只是重定向,如何设置配置?
假设这是多个域 ->
www.domainsite1.com/adminindex
www.domainsite1/landingpage
www.domainsite2.com/adminindex
www.domainsite2/landingpage
所以当我打开时
,它将打开
但 URL 保持不变
。
我已经将domainsite1 A记录设置为Nginx IP。 这是我当前的 Nginx 配置:
server {
listen 80 default_server;
#listen 443 ssl;
server_name www.domainsite1.com/;
location / {
# proxy_set_header Host $host;
# proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass https://www.mainsite.com/index;
# Add the trailing slash
# rewrite ^([^.]*[^/])$ $1/ permanent;
}
}
server {
listen 80 default_server;
#listen 443 ssl;
server_name www.domainsite2.com/;
location / {
# proxy_set_header Host $host;
# proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass https://www.mainsite.com/index;
# Add the trailing slash
# rewrite ^([^.]*[^/])$ $1/ permanent;
}
}
谢谢。
I have 1 app in a server.
www.mainsite.com/adminindex
www.mainsite.com/landingpage
And I would like multiple domains to be able to open this app and still mask/proxy the domain URL using Nginx. But whichever configuration I did, it just redirect, how do set the configuration ?
Let say this is the multiple domains ->
www.domainsite1.com/adminindex
www.domainsite1/landingpage
www.domainsite2.com/adminindex
www.domainsite2/landingpage
So when I open
, it will open the
but the URL stays the same
.
I have already set domainsite1 A record to the Nginx IP.
This is my current Nginx configuration :
server {
listen 80 default_server;
#listen 443 ssl;
server_name www.domainsite1.com/;
location / {
# proxy_set_header Host $host;
# proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass https://www.mainsite.com/index;
# Add the trailing slash
# rewrite ^([^.]*[^/])$ $1/ permanent;
}
}
server {
listen 80 default_server;
#listen 443 ssl;
server_name www.domainsite2.com/;
location / {
# proxy_set_header Host $host;
# proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass https://www.mainsite.com/index;
# Add the trailing slash
# rewrite ^([^.]*[^/])$ $1/ permanent;
}
}
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果只是您的域名不同,并且您想将其解析为多个地址而不更改
uri
,则可以使用此功能,只需将域名保留在proxy_pass
中即可>/无论域名是什么,最终都会解析为 -
www.example.com/xxxx/
->/xxxx/
->https://www.mainsite.com/xxxx
www.exampletwo.com/yyyy/
->/yyyy/
->https://www.mainsite.com/yyyy
ww.examplethird.com
,-> <代码>/ ->https://www.mainsite.com/
如果您想了解更多信息 - 链接
If only your domain name is different and you would like to resolve it to several address with no changes in
uri
, You can use this just keep domain name inproxy_pass
with/
No matter what is the domain name, it will eventualy resolve to -
www.example.com/xxxx/
->/xxxx/
->https://www.mainsite.com/xxxx
www.exampletwo.com/yyyy/
->/yyyy/
->https://www.mainsite.com/yyyy
ww.examplethree.com
, ->/
->https://www.mainsite.com/
If you would like to know more info - Link