简体   繁体   中英

Can I have multiple domain names point to different subdirectories on the same server

I have two domain names www.blog.com and www.project.com

Currently, www.blog.com/project points to my project page. I have nginx configured to redirect any requests to /project to my Django project.

I have just purchased www.project.com , and I would like it to display the same content as www.blog.com/project without it's URL changing in the browser. I'm not sure if there is a way to do this with DNS (a redirect won't preserve the URL), or a way to determine if a request came from www.blog.com or www.project.com at the server level.

In short:

  1. blog.com stays pointing to root
  2. blog.com/project needs keep being forwarded to Django
  3. project.com now needs to appear in the browser bar and perform like 2.

Richard Smith nailed it. Creating a new server block was the way to go. I've included the relevant parts of the .conf file in case anyone runs into this issue.

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/; 
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM