PiranhaCMS / piranha.core.docs

Official documentation for Piranha CMS
MIT License
12 stars 51 forks source link

Running multiple sites with Nginx proxy pass #93

Closed lukasan closed 2 years ago

lukasan commented 2 years ago

I'm using .NET 5, PiranhaCMS 9.2.0

When following the instructions in https://piranhacms.org/docs/v9/tutorials/how-to-use-multitenancy, on Windows everything works as expected. On production Ubuntu 20.04.

I added values to the /etc/hosts file analogous to the tutorial's Windows:

127.0.0.1 localhost/en
127.0.0.1 localhost/ru

Added two additional sites in the manager with localhost/en and localhost/ru endpoints.

curl localhost:5000/en from inside the server returns me 200 OK with the correct content set.

with Nginx I have the config as follows:

server {
    listen        80;
    server_name   _;
    location / {
        proxy_pass         http://localhost:5000;
        proxy_http_version 1.1;
        proxy_set_header   Upgrade $http_upgrade;
        proxy_set_header   Connection keep-alive;
        proxy_set_header   Host $host;
        proxy_cache_bypass $http_upgrade;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Proto $scheme;

        proxy_buffer_size          128k;
        proxy_buffers              4 256k;
        proxy_busy_buffers_size    256k;
}

The default site works as expected, but when going to another language config like localhost/en or localhost/ru that should translate to server_ip/en and server_ip/ru, I get 404.

I tried adding another location (with variations commented-out and not limited to them):

   location /en/ {
        proxy_pass         http://localhost:5000;
#       proxy_pass         http://localhost:5000/en;
#       rewrite            ^/$ http://localhost:5000/en redirect; #permanent
        proxy_http_version 1.1;
#       proxy_redirect     off;
        proxy_set_header   Upgrade $http_upgrade;
        proxy_set_header   Connection keep-alive;
        proxy_set_header   Host $http_host;
        proxy_cache_bypass $http_upgrade;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Proto $scheme;

        proxy_buffer_size          128k;
        proxy_buffers              4 256k;
        proxy_busy_buffers_size    256k;
   }

What I don't understand is how it should be mapped, since it uses hosts file to work.

I believe it would be a fairly common use-case and should be even added to the documentation tutorial mentioned above.

Thanks

lukasan commented 2 years ago

Yeah, after tinkering I figured the fix is as simple as it can get:

on the manager, I had to change the Hostnames input to: public_ip/en, and not the internal localhost link. No need to edit Nginx for this. Silly me, I guess...