I'm using Ubuntu 18.04, and I have just finished installing LEMP on my local machine. I'm having trouble figuring out how to host multiple sites on nginx. For example, I have a site called "test" and it's located in /var/www/test -> index.php. But when I run the server at: localhost/test/index.php it gives me a 404 error Not Found.
I have added and named the file as "test" to both at sites-available and sites-enabled and restarted nginx and it still didn't work. The original was named default but changed it to example.com because I was following the tutorial on how to install LEMP. I even moved the example.com from sites-available and sites-enabled to the desktop to avoid conflict.
This is my sites available code:
server { listen 80; root /var/www/test; index index.php index.html index.htm; server_name test; location / { try_files $uri $uri/ =404; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/var/run/php/php7.3-fpm.sock; }
}Also, after the installation of LEMP I tested a quick script just echoing out the phpinfo(); and it worked, so I know PHP works. I also have PHPmyadmin and that works, too. I think it's a path issue that I am going wrong here. It's obvious that I am a beginner at Ubuntu which is why I am here. Lol
Perhaps the method that I am trying to achieve isn't possible? I would like to have all my sites under this structure: /var/www/sitenamegoeshere
Because according to tutorials I've been only seeing structures such as: /var/www/sitenamegoeshere/public_html
Any help will be greatly appreciated it! If needed additional information regarding my LEMP setup, definitely ask me. Thanks
1 Answer
Looking at your configuration you should be able to tell the issue yourself:
server_name test;You are telling it to only react to the name test (so-called "virtual host") but you access it via the name localhost. How is that supposed to work?
For your test setup try editing /etc/hosts and include a line like this:
127.0.0.1 test... restart nginx (e.g. service nginx restart as root) ... and then try to access it again under that name ... should work, unless you forgot to mention some other relevant detail(s).