【问题标题】:Nginx; use blog.example.com to access example.com/blogNginx;使用 blog.example.com 访问 example.com/blog
【发布时间】:2012-03-03 08:16:01
【问题描述】:

我在一天的大部分时间里都在努力解决这个问题。

我希望能够使用子域访问服务器上的目录/文件,而无需更改客户端 URL。请原谅我使用了不正确的技术术语。

我可以这样做:

if ($host = 'blog.example.com') {
    rewrite  ^/(.*)$  http://example.com/blog/  permanent;
}

除非更改 URL。如果有人能为我指出正确的方向,将不胜感激。

提前致谢。

【问题讨论】:

    标签: redirect nginx subdomain


    【解决方案1】:

    您需要为子域设置一个 nginx 服务器配置,将它的 document_root 设置为 /path/to/www/htdocs/blog,它应该可以很好地处理它。

    server {
        server_name blog.example.com;
        root  /path/to/www/htdocs/blog;
    
        location / {
            index index.php index.html index.htm;
        }
        # any other configuration needed for the sub domain.
    }
    

    应该这样做。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-22
      • 2019-05-18
      • 2020-06-20
      • 1970-01-01
      相关资源
      最近更新 更多