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: 1.com Sub.1.com 2.com
Where 2.com should point to the subdomain sub.1.com. On sub.1.com 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;
server_name 1.com;
return 301 $scheme://2.com$request_uri;
}<^>
}
It seems that the server entry is not sufficient. I am now unsure what else I need to change.
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!
Hey, I am sorry. There are missleading information in my question and some information missing.
So this part should look like this:
<^> server_name 2.com;
return 301 $scheme://sub.1.com$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: https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-virtual-hosts-server-blocks-on-ubuntu-12-04-lts-3
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 example.com to sub.example.com.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.