Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've urls on my site that have nested urls encoded by encodeURI function.

My site is running using nginx 0.8.53 The problem is that when nginx gets such url it decodes the whole url and remove double slashes passing incorrect url down to passenger and then in my ruby code. Here is my general nginx configuration:

daemon off;

user  www-data;
pid   /var/run/;
worker_processes  1;

events {
    worker_connections  1024;

http {
    passenger_root /usr/local/rvm/gems/ruby-1.9.2-p136@global/gems/passenger-3.0.2;
    passenger_ruby /usr/local/rvm/wrappers/;

    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    tcp_nodelay        on;

    gzip  on;

    keepalive_timeout  65;

    server {
        listen       80;
        server_name  localhost;

        log_format combined-realip '$remote_addr ($http_x_real_ip) - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent"';
        access_log /opt/nginx/logs/access.log combined-realip;

        if (-f /home/ {
            return 503;

        root /home/;
        passenger_enabled on;

        rack_env production;
        passenger_set_cgi_param SERVER_NAME $http_host;

        error_page 503 /503.html;
        location = /503.html {
            root   html;

        include /home/*nginx.conf;

I tried setting merge_slashes to off in /home/

merge_slashes off;

but it didn't work. I don't have any ideas except start passenger as standalone and use proxy_pass, but another problem is that I'm using cloud service which provides nginx and passenger and I can only edit that /home/ and nothing else.

Please help me.

share|improve this question
Are you sure that nginx was restarted so that 'merge_slashes' option was really applied? – AlexD Jun 27 '11 at 12:47
yes, restarted couple of times, still doesnt work – sha1dy Jun 27 '11 at 14:01

merge_slashes only works as a directive in a server block when that server is a default server. Specify it instead in your http block.

Note however that even with merge_slashes off, nginx will still decode the slashes, and Passenger will still merge them. I worked around this on my site by looking for things like "http:/" in my action and modifying them appropriately:

missing_double_slash_match = /\A([a-z]+)\:\/([^\/])/.match(term)
if !missing_double_slash_match.nil?
    term = term.sub(missing_double_slash_match[0], "#{missing_double_slash_match[1]}://#{missing_double_slash_match[2]}")
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.