F
F
frolin2016-01-22 18:47:02
Nginx
frolin, 2016-01-22 18:47:02

How to configure nginx to dynamically substitute the path to the folder after the domain?

Good afternoon. I'm trying to set up nginx for dynamic url substitution in file paths.
What I mean.
There is a demo.server.ru path.
I want nginx to look at demo.server.ru/$path requests
and send them to /var/www/apps/demo/$path
That's how I'm trying to do it, but stubbornly refuses to send it to the path.

server {
    listen 80;
    server_name  demo.server.ru;
    root /var/www/apps/demo/;
    location ^(.*) {
        set $path $1;
        passenger_enabled on;
        root /var/www/apps/demo/$path/current/public;
    }
}

I tried that too but didn't succeed :(
try_files $uri /var/www/apps/demo/$uri/current/public;

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
frolin, 2016-01-22
@Fralunia

RESOLVED!

server {
    listen 80;
    server_name demo.server.ru;
    root /var/www/apps/demo;

        location ~ /?(.*)$ {
            set $path $1;
            alias /var/www/apps/demo/$path/current/public/;
            passenger_enabled on;
        }
}

the only thing, so far, not a very beautiful way is obtained (additional slashes).
but another snag appeared, how to tell rails that its base_path != '/' , and tried to write '/sitename'
in enviroments/production.rb - it didn't help.
config.relative_url_root = "/sitename"
config.action_controller.relative_url_root = "/sitename"

A
Andrey Burov, 2016-01-22
@BuriK666

you can make demo.server.ru directory and use
root /var/www/apps/$host/$path/current/public;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question