0

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

I would like to have :

  • 1.2.3.4 pointing to /var/www/html/website1
  • 1.2.3.4/ws2 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:

website1:

server {
    listen 80;
    server_name localhost;
}

website2:

server {
    listen 80;
    server_name localhost/ws2;
}

1 Answer 1

2

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

server {
    listen 80;
    server_name 1.2.3.4;

    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.

4
  • 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, 2019 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 1.2.3.4 server.
    – Lenniey
    Aug 13, 2019 at 11:49
  • I get "404 Not Found" when trying the configuration in the main answer.
    – DevonDahon
    Aug 13, 2019 at 11:55
  • You need to adapt the paths in the snippet to the actual locations of your websites.
    – wedi
    Aug 13, 2019 at 12:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .