Score:0

How to setup nginx on a subfolder

br flag

I bought a VPS running Ubuntu 20.04. I am fairly new to all the hosting and Linux stuff and I’m struggling on setting up the following situation or if this is even possible:

I have my /var/www folder which has many subfolders. Each holds a website. I want, if someone access my domain (e.g. mydomain.com) he should see the folder /var/www/codeiginiter4/. But when someone excess mydomain.com/foldername he should see the content of the /var/www/foldername/.

What makes it a little more tricky: CodeIgniter uses the following .htaccess for apache:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

This applies the mydomain.com/foo to mydomain.com/index.php/foo for the CodeIgniter SEO friendly URL routing. For nginx they provide

location / {
    try_files $uri $uri/ /index.php$is_args$args;
}

I got it working with

location ~* ^/(assets|files|robots\.txt) { }

But I have the issue that whatever you add after mydomain.com/ will route to my CodeIgniter folder instead of other websites in other folders.

From my understanding try_files $uri $uri/ /index.php$is_args$args; will check $uri (a file), then a folder $uri/ first, so it should serve a folder if there is one, but I always end in my CodeIgniter page.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.