Redirect from domain to subdomain

Hello dear community

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

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.

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

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.

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