Skip to main content

Forums

This topic contains 10 replies, has 2 voices, and was last updated by  chrisburton 4 years, 7 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #186003

    chrisburton
    Participant

    I can’t seem to find a tutorial that works.

    I’m trying to redirect an old domain and anything typed after / to redirect to a new domain.

    For example ( => equals redirect ):

    domain.net => domain.me
    domain.net/something => domain.me/something

    #186004

    Alen
    Participant

    Try

    
    location / {
        rewrite ^(.*)$ http://www.domain.me/$1 redirect;
    }
    
    #186007

    Alen
    Participant

    Nginx config file domain.net.conf in /etc/nginx/sites-available, don’t forget to system link it to sites-enabled folder and reboot Nginx.

    
    server {
    
            listen 80;
            server_name domain.net;
            root /folder/on/the/server/www;
    
            location / {
                rewrite ^(.*)$ http://www.domain.me/$1 redirect;
            }
    
            location ~ /\.ht {
                deny all;
            }
    }
    
    #186009

    Alen
    Participant

    Each of the domains that your server is responding to should have its own config file. So if you are responding to domain.net and domain.me each needs seperate config files. You would place these in the sites-available folder. Then you would system link them, similar to what a2ensite does for Apache, to the sites-enabled.

    sudo ln -s /etc/nginx/sites-available/domain.me.conf /etc/nginx/sites-enabled/domain.me.conf

    sudo service nginx reload

    #186011

    Alen
    Participant

    The names are not really important. That’s more for our conviniance. Server name and document root we really care about. Nginx just loads the config files. You can have eveyrthing in one file if you wanted to.

    So I would leave the default as is. If that’s your main website, then just copy that config file, name it old.site.config if you want, then just add the code above, responding to appropriate domain. It’s really up to you how you want to structure it.

    #186012

    Alen
    Participant

    EDIT: Linked to wrong video, this one is using wildcard subdomains. I’ll leave it here if someone find it useful. Let me go find the correct one.

    Watch this and you’ll see the process: https://serversforhackers.com/editions/2014/03/25/nginx/

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.

icon-link icon-logo-star icon-search icon-star