2

I have 2 sites in one debian machine. Currently one is running on port 443/80 and another one is running on port 8090. My requirement is to run both sites on 443 and if I enter site.com/1 - I should be redirected to site 1 and if I enter site.com/2 - I should be reached to site 2. How to achieve this with nginx?

I have tried proxying but the problem is - If I use the same port for both listen's it's ignoring stating already in use.

karikevinod
  • 633
  • 7
  • 16

1 Answers1

1

As per your requirement you want to run two sites with same domain. Lets say

example.com/site1
example.com/site2

for this you need to modified the nginx configuration file as per the following template open the nginx config file assosiated to example.com domain and add following code.

    server {
      listen 80;
      server_name  example.com;
      return 301 https://example.com$request_uri;
    }

    server {
      listen 443 ssl http2;
      server_name example.com; 
      modsecurity_transaction_id "example.com-$request_id"; 
      access_log           /var/log/nginx/access.log; 
      error_log            /var/log/nginx/error.log; 
      include              /etc/nginx/default.d/example.com/*.conf;
location / {
            try_files $uri $uri/ =404;
    }


    location /site1 {
            index index.php index.html index.htm;
            try_files $uri $uri/ /site1/index.php?q=$uri&$args;
    }

    location /site2 {
            index index.php index.html index.htm;
            try_files $uri $uri/ /site2/index.php?q=$uri&$args;
    }
}