Spurious "/.com" inserted into URL

desiato nginx-forum at nginx.us
Mon Aug 9 22:03:27 MSD 2010


(You can see this pretty-printed at
http://serverfault.com/questions/168098/nginx-just-started-inserting-spurious-coms-into-our-urls
)

I made some minor changes to our nginx config on Friday (deploying SSL
certs: adding a server listening on 443 with the appropriate settings
and adding a couple rewrite rules to forward certain requests to it) and
all of a sudden our URLs started getting extra "/.com"s inserted into
them.  For example, clicking a link to http://domain.com/logout/ takes
the user to http://domain.com/logout/.com/.  http://domain.com/register/
forwards to http://domain.com/.com/register/.  This doesn't happen with
a subdomain (e.g. http://production.domain.com/logout/ just works) and
it also doesn't happen with https://domain.com/ (so right now, as a
workaround, the entire site is being served with https).

Our nginx serves static content and proxies dynamic requests to Apache,
which is pretty standard for Django.  This had been working fine for
months; I have no idea why it stopped working.  I can't even be sure the
problem is at the nginx level, but that's the only thing I changed, so
that's where my attention has been.

Any help/suggestions would be greatly appreciated.

Here are the relevant config files (again, the link above has this
formatted nicely):


[quote=nginx.conf]
#######################################################################
#
# This is the main Nginx configuration file.  
#
# More information about the configuration options is available on 
#   * the English wiki - http://wiki.codemongers.com/Main
#   * the Russian documentation - http://sysoev.ru/nginx/
#
#######################################################################

#----------------------------------------------------------------------
# Main Module - directives that cover basic functionality
#
#   http://wiki.codemongers.com/NginxMainModule
#
#----------------------------------------------------------------------

user              nginx;
worker_processes  4;

error_log         /var/log/nginx/error.log;
#error_log        /var/log/nginx/error.log  notice;
#error_log        /var/log/nginx/error.log  info;

pid               /var/run/nginx.pid;



#----------------------------------------------------------------------
# Events Module 
#
#   http://wiki.codemongers.com/NginxEventsModule
#
#----------------------------------------------------------------------

events {
    worker_connections  1024;
}


#----------------------------------------------------------------------
# HTTP Core Module
#
#   http://wiki.codemongers.com/NginxHttpCoreModule 
#
#----------------------------------------------------------------------

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local]
$request '
                      '"$status" $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;

    keepalive_timeout  65;

    # Load config files from the /etc/nginx/conf.d directory
    include /etc/nginx/conf.d/*.conf;

    # the upstream apache server
    upstream django {
        server  localhost:9000;
    }

    upstream blog {
        server  localhost:9001;
    }

    server {
        listen      80;
        server_name www.domain.com beta.domain.com;
        rewrite ^/(.*) http://domain.com/$1 permanent;
    }


    server {
        listen      80;
        server_name domain.com production.domain.com;
        root    /var/www/domain.com/;
        access_log  /var/log/nginx/domain.com.access.log;

        location ~ ^/blog/ {
            proxy_set_header     Host             $host;
            proxy_pass           http://blog;
        }

        location / {

            proxy_set_header X-Forwarded-For
$proxy_add_x_forwarded_for;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;

            if (-f $request_filename/index.html) {
                rewrite (.*)    $1/index.html break;
            }

            if ($request_filename ~ "/register/") {
                rewrite ^/(.*)  https://domain.com/$1 permanent;
            }

            if ($request_filename ~ "/accounts/subscription/") {
                rewrite ^/(.*)  https://domain.com/$1 permanent;
            }

            # temporary workaround for weird .com bug
            rewrite ^/(.*)  https://domain.com/$1 permanent;

            if (!-f $request_filename) {
                proxy_pass         http://django;
            }
        }
    }

    server {
        listen 443;
        server_name domain.com production.domain.com;
        root /var/www/domain.com/;
        access_log /var/log/nginx/domain.com.https.access.log;
        error_log /var/log/nginx/domain.com.https.error.log;

        ssl on;
        ssl_certificate /etc/nginx/conf.d/full.crt;
        ssl_certificate_key /etc/nginx/conf.d/pass_server.key;
        ssl_prefer_server_ciphers on;

        location / {

            if (-f $request_filename/index.html) {
                rewrite (.*) $1/index.html break;
            }
            if (!-f $request_filename) {
                proxy_pass http://django;
            }
[/quote]


[quote=conf.d/virtual.conf]
server {
    listen      80;
    server_name 11.22.33.44;
    root    /var/www/domain.com/;
    access_log  /var/log/nginx/domain.com.directip.access.log;

    location / {
        if (-f $request_filename/index.html) {
            rewrite (.*)    $1/index.html break;
        }
        if (!-f $request_filename) {
            proxy_pass         http://django;
        }
    }

}
[/quote]

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,117878,117878#msg-117878




More information about the nginx mailing list