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.
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.
×