Question

nginx multiple domains on one droplet configuration

Hi, I am having some issues with setting multiple domains on one droplet as the 2nd and 3rd subdomains point to the same folder of the 1st domain. I have domain1 set up and working. The 2nd and 3rd server blocks I add are showing me the website I set up for the 1st domain. I symlinked the conf files from sites-available with sites-enabled, added the dns records on digital ocean admin and send them to someone else to set them in the domain name registrar dns records. These are the server blocks I have in sites-available along with the default config file: domain1.com

server {

	root /var/www/domain1.com/html;

	index index.html index.php index.htm index.nginx-debian.html;

	server_name domain1.com www.domain1.com;

	location / {
		
		try_files $uri $uri/ =404;
	}


	location ~ \.php$ {
		include snippets/fastcgi-php.conf;
	
		fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
		
	}


    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/domain1.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/domain1.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot


}

server {
    if ($host = www.domain1.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    if ($host = domain1.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


	listen 80;
	listen [::]:80;

	server_name domain1.com www.domain1.com;
    return 404; # managed by Certbot




}

lp.domain2.com

server {
	listen 80;
	listen [::]:80;


	root /var/www/lp.domain2.com/html;

	index index.html index.php index.htm index.nginx-debian.html;

	server_name lp.domain2.com;

	location / {
		
		try_files $uri $uri/ =404;
	}


	location ~ \.php$ {
		include snippets/fastcgi-php.conf;
	
		
		fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
		
	}
}

lp.domain3.com

server {


	root /var/www/lp.domain3.company/html;

	index index.html index.php index.htm index.nginx-debian.html;

	server_name lp.domain3.company www.lp.domain3.company;

	location / {
		
		try_files $uri $uri/ =404;
	}

	
	location ~ \.php$ {
		include snippets/fastcgi-php.conf;
	
		fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
	
	}


}


What am I doing wrong here? I can’t figure it out.


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.

Accepted Answer

I managed to find the issue: The company holding the domains were redirecting from http to https before pointing the DNS to my droplet. the only server block with SSL was my domain1 config file and all https request were pointing to this domain root folder. I added listen 443 ssl; listen [::]:443 ssl;

to the other server blocks

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hi there,

The Nginx configuration looks correct. A possible problem here could be that the user that Nginx is running as, does not have permissions to the directories in question. You could try setting the owner of the files and folders to the Nginx user.

Also, I could suggest checking your error log to verify if this is the case:

  1. sudo tail -100 /var/log/nginx/error.log

Let me know how it goes! Regards, Bobby