nginx uwsgi 配置泛二级域名解析失败

发布于 2022-09-01 18:07:15 字数 1398 浏览 13 评论 0

需求(以sina.com为例):
http://abc.sina.comhttp://www.sina.com/blog/abc
http://abc.sina.com/picshttp://www.sina.com/blog/abc/pics
网址要隐式的,地址栏显示 http://abc.sina.com/pics

server{
    listen   80; ## listen for ipv4; this line is default and implied

    server_name sina.com www.sina.com *.sina.com;

set $subdomain '';
if ( $host ~* (\b(?!www\b)\w+)\.sina\.com ) {
set $subdomain $1;
set $suburl $request_uri;
}




    location / {
          proxy_redirect off;
                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_pass http://sina.com;
           if ( $suburl ~ "/$" ) {
              rewrite ^/(.*) /blog/$subdomain break;
           }
           root /var/www/sina.com/;
           uwsgi_pass 127.0.0.1:8082;
           include uwsgi_params;
    }

    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css)$
    {
      root /var/www/sina.com/;
      access_log off;
      expires 30d;
      break;
    }
}

                             

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文