Search code examples
ruby-on-railsrubynginxpassengerproxypass

Nginx redirect to sign in


My proxy pass go in example:7456/nix/sign_in, but when I type login and password, and click submit button server not stay on example:7456/nix/sign_in and redirect to example:7456/sign_in.

  server {
    listen 7456;
    charset utf-8;
    server_name example;
    root /home/support/project_test/public;
    passenger_enabled on;
    rails_env development;

    location /nix/ {
        root /home/support/project_nginx/public;
        passenger_base_uri /nix/;
        passenger_enabled on;
        #include proxy_params;
        proxy_pass http://10.77.92.167:7458/;
        #proxy_set_header X-Accel-Redirect;
        proxy_pass_header X-Accel-Redirect;
        proxy_set_header Content-Length 0;
        proxy_set_header Host $host;
        proxy_redirect off;
    }
}
server {
    listen 7458;
    charset utf-8;
    server_name example;
    root /home/support/project_nginx/public;
    passenger_enabled on;
    rails_env development;
}

How can I fix redirect and stay example:7456/nix/ — on proxy pass.

I use Nginx, Passenger and Ruby on Rails.


Solution

  • First go to environment.rb

    ENV['RAILS_RELATIVE_URL_ROOT'] = "/nix/"
    

    Second config.ru

    map '/nix/' do
      run App::Application
    end
    

    And next nginx.conf

    location /nix/ {
       proxy_pass http://example:7458/nix/;
       proxy_set_header Host $host;
    }
    

    Type http://example:7456/nix/sign_in, and you did'n get redirect to another page, when click submit button.