[英]Is it possible to use nginx and redirect to correct path based on sub domains?
I spot an issue when trying to configure the server.我在尝试配置服务器时发现了一个问题。 On the server side I am using Nginx.在服务器端,我使用的是 Nginx。
The issue is that I got 1 domain and 2 subdomains like:问题是我有 1 个域和 2 个子域,例如:
And these 3 urls are redirected to server with IP by Record A.并且这 3 个 url 被记录 A 重定向到带有 IP 的服务器。
All i want to do is recognize from what url the user comes and return:我想做的就是从 url 中识别用户来并返回:
I don't know how to recognize from what url the user comes.我不知道如何识别用户来自url。 Is it possible to do that?有可能这样做吗? If it is - just if you got some tutorials - i would be grateful, Unfortunately, I checked lots of tutorials.如果是的话——只要你有一些教程——我将不胜感激,不幸的是,我检查了很多教程。 but I wasn't able to manage it.但我无法管理它。
Just as a information, I'm really bad at that piece (servers and configuration) - but want to learn it:)作为一个信息,我在这方面真的很糟糕(服务器和配置) - 但想学习它:)
Thank you!谢谢!
The server_name
directive assigns rules to server
blocks for specific domain/host names: server_name
指令为特定域名/主机名的server
块分配规则:
server {
server_name test.com www.test.com;
listen 80; # IPv4
listen [::]:80; # IPv6
root /var/www/static-files;
}
server {
server_name api.test.com;
...
}
server {
server_name panel.test.com;
...
}
Alternatively, the $host
variable could be used within server blocks that serve multiple hosts:或者,可以在服务多个主机的服务器块中使用$host
变量:
server {
server_name test.com www.test.com
api.test.com
panel.test.com;
return 200 "This hostname is $host";
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.