-1

If I want to work locally with 3 sites

site1 site2 site3

How do I configure my nginx and host?

sites-available:

server_name site1

location / {
            proxy_pass http://127.0.0.1:81;
}

The other sites:

server_name site2

location / {
            proxy_pass http://127.0.0.1:82;
}

server_name site3

location / {
            proxy_pass http://127.0.0.1:83;
}

/etc/hosts:

127.0.0.1   site1
127.0.0.1   site2
127.0.0.1   site3

This does not work, they take me to the same site

Isaac Palacio
  • 149
  • 4
  • 12
  • Why using the proxy pass directive? – LeRouteur Sep 23 '20 at 06:20
  • 1
    You stated that this configuration is from the directory `sites-available`. On Debian based systems this directory is not included in the configuration, rather `sites-enabled` is. You need to create symlinks to the config files in `sites-available` in the `sites-enabled` directory. Do these symlinks exist? – Gerald Schneider Sep 23 '20 at 11:57
  • oohh I had not created the links – Isaac Palacio Sep 23 '20 at 22:25

1 Answers1

3

Why are you using the proxy_pass directive?

server {
    listen 80;
    root /var/www/site1;
    index index.html index.htm;
    server_name site1.local;

    location / {
        try_files $uri $uri/ =404;
    }
}

server {
    listen 80;
    root /var/www/site2;
    index index.html index.htm;
    server_name site2.local;

    location / {
        try_files $uri $uri/ =404;
    }
}

/etc/hosts:

127.0.0.1 site1.local site2.local

see also: https://www.nginx.com/resources/wiki/start/topics/examples/server_blocks/

LeRouteur
  • 388
  • 2
  • 16