claudioc / jingo

Node.js based Wiki
MIT License
1.02k stars 184 forks source link

nginx relative root problem #114

Closed creynold closed 8 years ago

creynold commented 8 years ago

I'm using NGINX with jingo. First I defined a server block:

server {
    listen 8080;
    server_name wiki;
    location / {
        proxy_pass http://127.0.0.1:6067/;
    }
}

Now if I browse to http://<server domain>:8080 everything works fine. I'd like to move this to http://<server domain>/wiki, however. But when I do this:

server {
    listen 80;
    server_name <server name>
    ...
    location /wiki {
        proxy_pass http://localhost:6067/;
    }
}

All of the urls in the jingo page are relative to the server root, and so no css/js files are loaded. Additionally it defaults to http://<server domain>/wiki/Home instead of http://<server domain>/wiki/wiki/Home.

Is there a way around this?

Thanks

almereyda commented 8 years ago

I suppose we can safely assume serving Jingo from non-root URL fragment is just not supported. One way for Jingo to be aware of such setups and be able to render different URLS could be an environment variable. This would be in accordance with http://12factor.net. Also I remember fiddling around with some baseUrl variable once, too.

On the other side, seperating different applications by subdomains is not only helpful regarding CSRF or XSS attacks. I propose not to support this scenario.

claudioc commented 8 years ago

It'd probably enough to make Jingo aware of being served ("mounted") in a subdirectory, the way WordPress does with WP_SITEURL configuration variable. As @almereyda mentioned, I am not really sure about all the consequences (WP introduced that option only from version 2.2), so I am not thinking to implement it right now. It should be easy to hack something in your local setup though.

almereyda commented 8 years ago

I propose to close this issue. nginx supports rewrite rules for proxy_pass. See https://raymii.org/s/tutorials/NGINX_proxy_folder_to_different_root.html for details.

Nevertheless the info gained should live in some kind of #117

creynold commented 8 years ago

I re-tried using rewrite rules:

location /wiki/ {
    rewrite ^/wiki(/.*)$ $1 break;
    proxy_pass http://127.0.0.1:6067/;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_redirect off;
}

The wiki pages are served correctly as far as I can tell, but the resources still fail to load (*.css, *.js, etc.). I guess this makes sense... I don't think there's a way to do this from NGINX.

I have another idea: could you add a config variable to specify the location of static files? A lot of other frameworks do this (e.g. Django).

claudioc commented 8 years ago

Closed in favour of #124