Welcome! Log In Create A New Profile

Advanced

Re: Spurious "/.com" inserted into URL

August 09, 2010 04:28PM
On Mon, Aug 09, 2010 at 02:03:27PM -0400, desiato wrote:

> (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.

Try to log $sent_http_location and $upstream_http_location to
see who sent wrong redirects.

> 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;
> }
> }

This configuration should rewritten as

location / {
try_files $uri/index.html $uri @django;
}

location @django {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://django;
}

location /register/ {
rewrite ^/(.*) https://domain.com/$1 permanent;
}

location /accounts/subscription/ {
rewrite ^/(.*) https://domain.com/$1 permanent;
}

> }
>
> 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;
> }

location / {
try_files $uri/index.html $uri @django;
}

location @django {
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]


--
Igor Sysoev
http://sysoev.ru/en/

_______________________________________________
nginx mailing list
nginx@nginx.org
http://nginx.org/mailman/listinfo/nginx
Subject Author Posted

Spurious "/.com" inserted into URL

desiato August 09, 2010 12:12PM

Re: Spurious "/.com" inserted into URL

vesperto August 09, 2010 02:18PM

Re: Spurious "/.com" inserted into URL

Igor Sysoev August 09, 2010 04:20PM

Re: Spurious "/.com" inserted into URL

desiato August 10, 2010 12:34AM

Re: Spurious "/.com" inserted into URL

Igor Sysoev August 09, 2010 04:28PM

Re: Spurious "/.com" inserted into URL

desiato August 09, 2010 05:25PM

Re: Spurious "/.com" inserted into URL

Maxim Dounin August 09, 2010 05:30PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 313
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready