I have two folders /var/www/html/website1 and /var/www/html/website2, and the ip of my server is

I would like to have :

  • pointing to /var/www/html/website1
  • pointing to /var/www/html/website2

What should I change or add to the server block of the two nginx configuration files website1 and website2 ?

Currently, I have the following configuration:


server {
    listen 80;
    server_name localhost;


server {
    listen 80;
    server_name localhost/ws2;

You only need a location block. In your case (for example):

server {
    listen 80;

    root /var/www/html/website1;

    location /ws2 {
        root /var/www/html/website2;

Note: this is the most basic configuration imaginable, it may suit your needs, or you may have to alter it accordingly.

  • I'd prefer to have a file per configuration instead of configuring the website2 in the website1 file. Adding the location block to the website2 file doesn't work. – DevonDahon Aug 13 '19 at 11:20
  • You configure a server and a location in this server. You don't have two websites, you only have one + a location. If you want to have two config files, you can define an include for /ws2 inside your server. – Lenniey Aug 13 '19 at 11:49
  • I get "404 Not Found" when trying the configuration in the main answer. – DevonDahon Aug 13 '19 at 11:55
  • You need to adapt the paths in the snippet to the actual locations of your websites. – wedi Aug 13 '19 at 12:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.