Question
Nginx and multiple sites issue on Ubuntu 20.04
I have a droplet for hosting three sites, all of them using Kirby CMS, a PHP based, flat-file CMS.
I followed this tutorial to setup Nginx and PHP: https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-ubuntu-20-04
I’ve setup a separate nginx config for each site, like so:
var/www/site1.com
var/www/site2.com
var/www/site3.com
Whenever I go to site1.com, it works as expected. When I go to site2.com, it looks like site 1, but the URL in the browser shows site1.com. If I go to site2.com/index.php I see the proper site that I expected.
Here’s what the site1 nginx config looks like:
server {
server_name site1.com www.site1.com;
root /var/www/site1.com;
index index.php index.html index.htm;
client_max_body_size 100M;
# Don't hint these as folders
rewrite ^/(content|site|kirby)$ /error last;
# block content
rewrite ^/content/(.*).(txt|md|mdown)$ /error last;
# block all files in the site and kirby folder from being accessed directly
rewrite ^/(site|kirby)/(.*)$ /error last;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ /panel {
autoindex off;
try_files $uri $uri/ /panel/index.php$uri&$args;
}
location ~ (?:^|/)\. {
deny all;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/site1.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/site1.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.site1.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = site1.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
server_name site1.com www.site1.com;
return 404; # managed by Certbot
}
Site 2’s config looks the same except the URLs are changed and it doesn’t have the Let’s Encrypt stuff yet since I can’t seem to get it to confirm ownership of the domains.
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.
×