我可以将多个域名指向同一服务器上的不同子目录

时间:2017-06-18 15:06:10

标签: django nginx dns webserver

我有两个域名www.blog.comwww.project.com

目前,www.blog.com/project指向我的项目页面。我已经将nginx配置为将任何请求重定向到我的Django项目{/ 1}}。

我刚刚购买了/project,我希望它显示与www.project.com相同的内容,而不会在浏览器中更改网址。我不确定是否有办法通过DNS执行此操作(重定向无法保留网址),或确定请求是来自www.blog.com/project还是{{1}的方法在服务器级别。

简而言之:

  1. www.blog.com一直指向root
  2. www.project.com需要继续转发给Django
  3. blog.com现在需要显示在浏览器栏中并执行类似2.

1 个答案:

答案 0 :(得分:0)

理查德史密斯钉了它。创建一个新的服务器块是要走的路。我已经包含.conf文件的相关部分,以防任何人遇到此问题。

server {
    listen 80;
    server_name .project.com;


    # set max upload size
    client_max_body_size 2G;
    fastcgi_buffers 64 4K;

    access_log /var/log/nginx/wordpress_http_access.log combined;


    #There were some shortsighted design decisions that meant it had to be
    # served from /project/ to avoid breaking a bunch of relative links.

    location = / {
        return 301 http://www.project.com/project/;


    }

    location /project/ {
            uwsgi_pass  django;
            include     /home/project/uwsgi_params;

    }
    # Django media
    location ^~ /project/media/  {
        alias /home/project/media/;  
            autoindex off;
}

location /project/static/ {
    alias /home/project/static/; 
    }
}