首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将nginx配置为代理,以便在HP云上使用devpi镜像。

将nginx配置为代理,以便在HP云上使用devpi镜像。
EN

Stack Overflow用户
提问于 2014-10-07 14:48:16
回答 1查看 1.8K关注 0票数 0

我试图在HP云上创建一个德皮镜像,它将通过nginx访问,即nginx侦听端口80,并用作在同一台机器上使用端口4040的devpi的代理。

我已经配置了一个hp云安全组,它为HP-cloud中的所有端口(入站和出站)打开(当然,在开始时,我将对其进行更改),并启动了一个ubuntu 14实例。

我已经为我创建的实例分配了一个公共IP。

我使用pip安装了devpi服务器,使用apt-get安装了nginx。

我遵循了devpi的指导页面这里上的说明

运行devpi-server --port 4040 --gen-config,并将在nginx-devpi.conf中创建的内容复制到nginx.conf中。

然后,我使用devpi-server --port 4040 --start启动了服务器。

使用sudo nginx启动nginx。

我的问题如下:当我是运行nginx和devpi的hp实例的SSHing时,执行pip install -i http://<public-ip>:80/root/pypi/ simplejson就成功了。

但是,当我在上运行相同的命令时--我的笔记本电脑--

代码语言:javascript
复制
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

我认为这可能是安全/网络问题,但我认为情况并非如此,因为curl http://<public-ip>:80在从我的笔记本电脑和从HP实例执行它时返回相同的内容:

代码语言:javascript
复制
{
  "type": "list:userconfig", 
  "result": {
    "root": {
      "username": "root", 
      "indexes": {
        "pypi": {
          "type": "mirror", 
          "bases": [], 
          "volatile": false
        }
      }
    }
  }
}

我还尝试在惠普云中启动另一个实例并执行pip install -i http://<public-ip>:80/root/pypi/ simplejson,但我得到的错误与我的笔记本电脑中的错误相同。

我不明白这两种情况之间有什么区别,如果有人能找到解决这个问题的办法,或者知道问题出在哪里,我会很高兴的。

我的nginx.conf文件:

代码语言:javascript
复制
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/*;
    }

编辑:--我尝试从我的笔记本上使用devpi-client,当我从执行devpi use http://<public-ip>:80 --我的膝上型计算机--我得到以下信息:

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

发布于 2015-01-07 05:52:37

您可以尝试从以下内容进行修改:

代码语言:javascript
复制
        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;
        }   

到这个

代码语言:javascript
复制
        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;
        }   

这是我的工作:-)。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26238803

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档