【问题标题】:Nginx prefix location configNginx 前缀位置配置
【发布时间】:2014-01-30 08:23:03
【问题描述】:

我将如何在 nginx vhost 中为域的前缀进行重写?

即:/var/www/site.com/public/ 以 /public 文件夹中的 /community 为根。

变成:浏览器中的community.site.com?

location /community {
    root /var/www/site.com/public/community/;
    rewrite "community."$document_root$uri.php;
}

我以前没有使用过前缀,这是完全错误的。我也找不到任何关于它的教程,所以我来到这里。

【问题讨论】:

    标签: nginx


    【解决方案1】:

    您正在尝试做的是称为子域,它是一个单独的服务器块,需要在 DNS 服务器中定义。

    server {
      server_name community.example.com;
      root /var/www/site.com/public/community/;
      location / {
        # change this to match ur site/framework working technique.
        try_files $uri $uri/ /index.php$request_uri;
      }
    }
    

    除非您确保 host community.example.com 会返回您的服务器 IP,否则这将不起作用,当然不要忘记重新启动/重新加载您的 nginx 服务。

    【讨论】:

    • 你可以说它是一个完全不同的域名,比如不是example1.comexample2.com,而是sub1.example.comsub2.example.com
    猜你喜欢
    • 1970-01-01
    • 2015-08-18
    • 2020-05-26
    • 1970-01-01
    • 1970-01-01
    • 2012-11-07
    • 2018-02-08
    • 2011-07-11
    • 2017-03-19
    相关资源
    最近更新 更多