configuring nginx as proxy to work with devpi mirror on HP-cloud

2.1k Views Asked by At

I'm trying to create a devpi mirror on HP-cloud that will be accessed via nginx, i.e - nginx listens to port 80 and used as a proxy to devpi that is using port 4040 on the same machine.

I have configured an HP-cloud security group that is opened for all ports (inbound and outbound) in hp-cloud (just for the beginning, I'll change it later of-course), and started an ubuntu 14 instance.
I have allocated a public IP to the instance that I have created.
I have installed devpi-server using pip, and nginx using apt-get.
I have followed the instructions on devpi's tutuorial page here:
ran devpi-server --port 4040 --gen-config, and copied the contents that was created in nginx-devpi.conf into nginx.conf.
Then, I have started the server using devpi-server --port 4040 --start.
Started nginx using sudo nginx.

My problem is as follows: When I'm SSHing to the hp-instance on which the nginx and devpi are running, and executing pip install -i http://<public-ip>:80/root/pypi/ simplejson it succeeded.

But, when I'm running the same command from my laptop I get

Downloading/unpacking simplejson
  Cannot fetch index base URL http://<public-ip>:80/root/pypi/
  http://<public-ip>:80/root/pypi/simplejson/ uses an insecure transport scheme (http). Consider using https if <public-ip>:80 has it available
  Could not find any downloads that satisfy the requirement simplejson
Cleaning up...
No distributions at all found for simplejson
Storing debug log for failure in /home/hagai/.pip/pip.log

I thought it might be security/network issue, but I think that this is not the case, because curl http://<public-ip>:80 returns the same thing when I'm executing it from my laptop and from the HP instance:

{
  "type": "list:userconfig", 
  "result": {
    "root": {
      "username": "root", 
      "indexes": {
        "pypi": {
          "type": "mirror", 
          "bases": [], 
          "volatile": false
        }
      }
    }
  }
}

I have also tried to start another instance in HP-cloud and execute pip install -i http://<public-ip>:80/root/pypi/ simplejson, but I got the same error as in my laptop.

I can't understand what is the difference between these two cases, and I'd be happy if someone would have a solution for this case, or any idea what might be the problem.

My nginx.conf file:

user www-data;
worker_processes 4;
pid /run/nginx.pid;

    events {
        worker_connections 768;
        # multi_accept on;
    }

    http {

        server {
            server_name localhost;   
            listen 80;
            gzip             on;
            gzip_min_length  2000;
            gzip_proxied     any;
            #gzip_types       text/html application/json; 

            proxy_read_timeout 60s;
            client_max_body_size 64M;

            # set to where your devpi-server state is on the filesystem
            root /home/ubuntu/.devpi/server;  

            # try serving static files directly
            location ~ /\+f/ {
                error_page 418 = @proxy_to_app;
                if ($request_method != GET) {
                    return 418; 
                }
                try_files /+files$uri @proxy_to_app;
            }
            # try serving docs directly
            location ~ /\+doc/ {
                try_files $uri @proxy_to_app;
            }
            location / {
                error_page 418 = @proxy_to_app;
                return 418;
            }
            location @proxy_to_app {
                proxy_pass http://localhost:4040;
                #dynamic: proxy_set_header X-outside-url $scheme://$host:$server_port;
                proxy_set_header  X-outside-url http://localhost:80;
                proxy_set_header  X-Real-IP $remote_addr;
            }   
        } 

        ##
        # Basic Settings
        ##

        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        # server_tokens off;

        # server_names_hash_bucket_size 64;
        # server_name_in_redirect off;

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

        ##
        # Logging Settings
        ##

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        ##
        # Gzip Settings
        ##

        gzip on;
        gzip_disable "msie6";

        #passenger_root /usr;
        #passenger_ruby /usr/bin/ruby;

        ##
        # Virtual Host Configs
        ##

        include /etc/nginx/conf.d/*.conf;
        #include /etc/nginx/sites-enabled/*;
    }

edit: I have tried to use devpi-client from my laptop, and when I've executed devpi use http://<public-ip>:80 from my laptop I get the following:

using server: http://localhost/ (not logged in)
no current index: type 'devpi use -l' to discover indices
~/.pydistutils.cfg     : no config file exists
~/.pip/pip.conf        : no config file exists
~/.buildout/default.cfg: no config file exists
always-set-cfg: no
1

There are 1 best solutions below

0
On

You can try modify from this:

        location @proxy_to_app {
            proxy_pass http://localhost:4040;
            #dynamic: proxy_set_header X-outside-url $scheme://$host:$server_port;
            proxy_set_header  X-outside-url http://localhost:80;
            proxy_set_header  X-Real-IP $remote_addr;
        }   

To this

        location @proxy_to_app {
            proxy_pass http://localhost:4040;
            proxy_set_header X-outside-url $scheme://$host;
            proxy_set_header  X-Real-IP $remote_addr;
        }   

This has been work for me :-).