Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I'm fairly new to web development, so I know I'm making a beginner mistake with my server configuration. I have an nginx server sitting in front of an Apache server that is serving Django requests. I have certain views that require login (through the @login_required decorator) and Django automatically redirects the user to /accounts/login/ if they access one of these views without being logged in. This works fine with http, but with https it redirects me to Apache's local IP address. For example, instead of getting redirected to https://staging.example.com/accounts/login, I get redirected to http://127.0.0.1:8080/accounts/login. Normal HTTPS requests work fine. I know my nginx and/or apache is misconfigured, but I don't know how.

Here is a part of my nginx config file:

server {
 listen   80;
 server_name  staging.example.com;
 root /path/to/staging/example.com/public_html/; 

 try_files $uri @django;

 #set your default location
 location @django  {
  proxy_pass         http://127.0.0.1:8080;
 }
 ...
}

server {

 listen 443;
 ssl on;
 ssl_certificate /path/to/cert-staging.example.com.crt;
 ssl_certificate_key /path/to/staging.example.com.key;
 server_name staging.example.com;

 try_files $uri @django;

 #set your default location
 location @django  {
   proxy_pass         http://127.0.0.1:8080;
   proxy_set_header   X-Forwarded-Protocol https;
 }
 ...
}

Here is a part of my Apache file:

NameVirtualHost * 
Listen 127.0.0.1:8080

<IfModule mod_ssl.c>
# If you add NameVirtualHost *:443 here, you will also have to change
# the VirtualHost statement in /etc/apache2/sites-available/default-ssl
# to <VirtualHost *:443>
# Server Name Indication for SSL named virtual hosts is currently not
# supported by MSIE on Windows XP.
Listen 443
</IfModule>

<IfModule mod_gnutls.c>
Listen 443
</IfModule>
share|improve this question

migrated from stackoverflow.com Dec 7 '11 at 0:58

This question came from our site for professional and enthusiast programmers.

1 Answer 1

up vote 0 down vote accepted

Well, that took forever to fix. I changed this in my nginx ports.conf:

proxy_redirect off;

to this:

proxy_redirect http://localhost:8080/ /

It kind of scares me that all of the examples I used seem to have proxy_redirect off, but I guess I'll keep it this way until someone can provide a better answer.

share|improve this answer

Your Answer

 
discard

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.