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

I would like to setup the following, as soon as I enter MySite.com in my local browser, I would like to be pointed at 127.0.0.1:8000.

I have done some research and it seems with nginx I could setup a reverse proxy on port 80 that will redirect traffic to Django port 8000.

I have been googeling for some time and did these steps.:

sudo vi /etc/nginx/sites-enabled/default

In there I edited the config file like this:

server {

        listen       80;
        server_name  MySite.com;

        root /usr/share/nginx/www;
        index index.html index.htm;

        location / {

        proxy_pass         http://127.0.0.1:8000/;
        proxy_redirect     off;

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

        client_max_body_size       10m;
        client_body_buffer_size    128k;

        proxy_connect_timeout      90;
        proxy_send_timeout         90;
        proxy_read_timeout         90;

        proxy_buffer_size          4k;
        proxy_buffers              4 32k;
        proxy_busy_buffers_size    64k;
        proxy_temp_file_write_size 64k;

        }
}

But this still doesn't work. What am I missing please?

UPDATE

Alright this is the latest version, which still doesn't work, it simply goes to the real MySite.com on Internet.

server {

    listen       80;
    server_name  MySite.com;

    root /usr/share/nginx/www;
    index index.html index.htm;

    location / {

            proxy_pass         http://127.0.0.1:8000/;
            proxy_redirect     http://MySite.com:8000/ /;

            proxy_set_header   Host             $host:$server_port;
            proxy_set_header   X-Real-IP        $remote_addr;
            proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
            proxy_max_temp_file_size 0;

            client_max_body_size       10m;
            client_body_buffer_size    128k;

            proxy_connect_timeout      90;
            proxy_send_timeout         90;
            proxy_read_timeout         90;

            proxy_buffer_size          4k;
            proxy_buffers              4 32k;
            proxy_busy_buffers_size    64k;
            proxy_temp_file_write_size 64k;

            }
share|improve this question
    
Could you please add more details about how it's doesn't work. What happend exacly? nginx fails to start? browsers gets redirected? –  rvs Jun 10 '12 at 18:08
    
I type in MySite.com and actually get to mySite.com instead of getting to 127.0.0.1:8000. (I have no apache running locally) –  Kave Jun 10 '12 at 18:16
    
@Kave , were you able to fix this issue? I see that in comments mysite.com was still pointing to real internet –  learner Jun 20 '12 at 13:09
add comment

2 Answers 2

up vote 0 down vote accepted

you are telling nginx to listen on port 80... I'm guessing apache is port 80. Your setup should be along these lines:

  server {
      listen 127.0.0.1:8000; # Real IP here
      server_name mysite.com;     # "_" is for handle all hosts that are not described by server_name
      charset off;
      access_log  /var/log/nginx_host_general.access.log  main;
      location / {   
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://127.0.0.1;    # Real IP here
        client_max_body_size       16m;
        client_body_buffer_size    128k;
      }

You are telling nginx to listen on port 8000, then do a proxy_pass to 127.0.0.1. You could define :80 here, but since http is port 80 by default you do not need to.

share|improve this answer
    
Thanks for your reply. On port 8000 a Django server is running, hence this wouldn't work. MySite.com should point to the Django server. –  Kave Jun 10 '12 at 17:53
    
Oh. your config should work then. What happens when you access the site? Does it load? I think it might be down to the option proxy_redirect off;, it should be proxy_redirect http://mysite.com:8000/ / . Also try adding $server_port to the header.. like so proxy_set_header Host $host:$server_port; –  Sc0rian Jun 10 '12 at 18:10
    
I have applied your suggestions and edited my question. What do you think? –  Kave Jun 10 '12 at 18:24
    
you say it just goes to the site on the internet.. Try changing proxy_redirect default or if that fails then proxy_redirect go to 127.0.0.1:8000, so it should be proxy_redirect http://127.0.0.1:8000/ / –  Sc0rian Jun 10 '12 at 18:32
    
I have tried both. It still goes to Internet :( –  Kave Jun 10 '12 at 18:42
show 2 more comments

Make sure you edit your /etc/hosts file so it doesn't try and translate www.mysite.com through external DNS. It should be an entry like this:

your_IP www.mysite.com   #your_IP is your actual IP address
share|improve this answer
add comment

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.