[英]nginx subdomain not redirecting to desired port
I have a requirement where I need to redirect subdomain to admin panel and domain to front facing part of site.我有一个要求,我需要将子域重定向到管理面板,并将域重定向到站点的正面部分。 I have created subdoamin in godaddy and used nginx on google compute engine.
我在godaddy中创建了subdoamin并在谷歌计算引擎上使用了nginx。
here are nginx conf settings which I am using:这是我正在使用的 nginx conf 设置:
Subdomain Rule子域规则
server {
listen 80;
listen [::]:80;
server_name admin.example.com;
root /var/www/html;
index index.html;
location / {
proxy_pass http://127.0.0.1:8000;
}
}
Main Site Rule主站点规则
server {
listen 80;
listen [::]:80;
server_name example.com;
root /var/www/html;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
both subdomain rule and main site rule are in file /etc/nginx/nginx.conf
子域规则和主站点规则都在文件
/etc/nginx/nginx.conf
The problem is, both "example.com" and "admin.example.com" goes to "example.com".问题是,“example.com”和“admin.example.com”都转到“example.com”。
I think, I did lot of googling but did not get solution.我想,我做了很多谷歌搜索,但没有得到解决方案。
Thanks in advance.提前致谢。
Your subdomain and Main site rule are same.您的子域和主站点规则相同。
root /var/www/html;
index index.html;
You can solve this problem by making another directory and subdomain conf:您可以通过创建另一个目录和子域 conf 来解决此问题:
root /var/www/site2/html;
index index.html
Make your subdomain conf file looks like:使您的子域 conf 文件如下所示:
server {
listen 80;
server_name admin.example.com;
location / {
proxy_pass http://127.0.0.1:8080;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.