Redirect from domain to subdomain

Posted May 26, 2021 244 views

Hello dear community

I have a simple setup: I own two domains and want to point one domain to a subdomain of the other.

Where should point to the subdomain On is running a wordpress in a plesk. I am seeking for real redirect, so that is why I have tried to store this in the nginx.conf.

var/etc/nginx.conf looks like this:

http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;
    #tcp_nodelay        on;

    #gzip  on;
    #gzip_disable "MSIE [1-6]\.(?!.*SV1)";

    server_tokens off;

    include /etc/nginx/conf.d/*.conf;

        <^>server {
                listen 80;
                return 301 $scheme://$request_uri;

It seems that the server entry is not sufficient. I am now unsure what else I need to change.

edited by bboucheron

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
2 answers

If you have two domain names then I would suggest you that redirect the first domain name to your WordPress subdomain using the DNS you are using. After that use Nginx to redirect to

Hey, I am sorry. There are missleading information in my question and some information missing.

So this part should look like this:

<^>                server_name;
                return 301 $scheme://$request_uri;<^>

I have everything on the same server. Therefore I cannot just edit the DNS for the domain. Since both domains are poiting to the same server, I think I need a redirect/server block.

This is very helpful:

But since I am running a plesk I dont have the “Sites-availabe” in my nginx or apache directory. I dont think that they are used, so I think this tutorial is not matching my issue.

The sites are stored in /var/vhosts and not in the folders mentioned in the tutorial.

by Etel Sverdlov
This tutorial shows you how to set up a new directory, how to grant the correct permissions, how to add content to a new page, how to turn on virtual hosting, and how to, if needed, set up local hosts. Virtual Hosts are used to run more than one website or domain off of a single server and IP address. When used with nginx, virtual hosts are called Server Blocks. This tutorial covers setting up server blocks on an Ubuntu server.