文章内容
2018/6/21 9:11:29,作 者: 黄兵
nginx 参数解析二级域名
最近需要将一个网站域名形如这样:http://pdflibr.com/SMS_Receive/index,解析成这样:http://sms.pdflibr.com/index
使用的是nginx,最好使用rewrite,操作方式:
修改配置文件,具体内容如下:
server {
listen 80;
server_name pdflibr.com;
index index,index.html;
location ~*^/SMS_Receive/ {
rewrite ^/SMS_Receive/(.*)$ http://sms.pdflibr.com/$1 permanent;
# Pass the request to Gunicorn
include proxy_params;
proxy_pass http://localhost:8000;
# Set some HTTP headers so that our app knows where the request really came from
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}当访问http://pdflibr.com/SMS_Receive/index的时候,出现了如下错误:

无法访问此网站,找不到ip地址,主要是因为没有做域名解析。
登陆云服务器提供商控制台,做域名解析:

做的是泛域名解析。等过一会儿再次访问,可以看到已经成功rewrite了。
黄兵个人博客原创。
转载请注明出处:黄兵个人博客 - nginx 参数解析二级域名
评论列表