By Jason Land
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.
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!
Hi @jasonland,
The config file looks fine. I can think of two things happening here. The first one: are you accessing site2.com via https? If you have no SSL on that website and try to load it, it will show the first website it finds with SSL. What I’m trying to say is, make sure you don’t have an https redirection.
The second thing I can think of is if you have somewhere in your site2.com’s database configured the url for site1. Can you confirm if those are not actually correct as well?
Regards, KFSys
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.