gpt4 book ai didi

ssl - 如何使用 https 服务 devpi?

转载 作者:太空宇宙 更新时间:2023-11-03 14:27:13 29 4
gpt4 key购买 nike

我有一个开箱即用的 devpi-server 在 http://上运行

我需要让它在 https://上运行。

我已经有了域的证书。

我关注了 documentation对于 nginx-site-config,并创建了 /etc/nginx/conf.d/domain.conf 文件,其中包含指向我的证书的 server{} block (摘录如下)。

但是,我的 devpi-server --start --init 完全忽略了任何/所有 nginx 配置。我如何指向 devpi-server 使用 nginx 配置?这有可能吗,还是我完全没有捕获要点?

/etc/nginx/conf.d/domain.conf 文件内容:

server {
server_name localhost $hostname "";

listen 8081 ssl default_server;
listen [::]:8081 ssl default_server;
server_name domain;
ssl_certificate /root/certs/domain/domain.crt;
ssl_certificate_key /root/certs/domain/domain.key;
ssl_protocols TLSv1.1 TLSv1.2;
ssl_ciphers EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH;

gzip on;
gzip_min_length 2000;
gzip_proxied any;
gzip_types application/json;

proxy_read_timeout 60s;
client_max_body_size 64M;

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

# try serving static files directly
location ~ /\+f/ {
# workaround to pass non-GET/HEAD requests through to the named location below
error_page 418 = @proxy_to_app;
if ($request_method !~ (GET)|(HEAD)) {
return 418;
}

expires max;
try_files /+files$uri @proxy_to_app;
}
# try serving docs directly
location ~ /\+doc/ {
try_files $uri @proxy_to_app;
}
location / {
# workaround to pass all requests to / through to the named location below
error_page 418 = @proxy_to_app;
return 418;
}
location @proxy_to_app {
proxy_pass https://localhost:8081;
proxy_set_header X-outside-url $scheme://$host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto https;
}
}

最佳答案

这是我在 superuser 上对同一问题的回答.

Devpi 对 Nginx 一无所知,它只会处理 HTTP 流量。当我们想通过 HTTPS 与 Web 应用程序交互时,作为客户端,我们需要与可以处理它的前端 (Nginx) 对话,后者将反过来与我们的 Web 应用程序通信。此 Nginx 应用程序称为 reverse proxy .作为反向代理,我们还可以受益于 Nginx 提供静态文件的能力,这比让我们的 Web 应用程序自己处理静态文件更有效(因此 “尝试提供服务...” 位置 block )。

这是我用于 devpi 的完整工作 Nginx 配置。请注意,这是 /etc/nginx/nginx.conf 文件,而不是像您这样的域配置,因为我在 docker 中使用 compose 运行 Nginx 和 Devpi,但您应该能够提取您需要的内容:

worker_processes 1;

events {
worker_connections 1024;
}

http {
# Define the location for devpi
upstream pypi-backend {
server localhost:8080;
}

# Redirect HTTP to HTTPS
server {
listen 80;
listen [::]:80;
server_name _;
return 301 https://$host$request_uri;
}

server {
listen 443 ssl;
server_name example.co.uk; # This is the accessing address eg. https://example.co.uk

root /devpi/server; # This is where your devpi server directory is
gzip on;
gzip_min_length 2000;
gzip_proxied any;

proxy_read_timeout 60s;
client_max_body_size 64M;

ssl_certificate /etc/nginx/certs/cert.crt; Path to certificate
ssl_certificate_key /etc/nginx/certs/cert.key; Path to certificate key

ssl_session_cache builtin:1000 shared:SSL:10m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
ssl_prefer_server_ciphers on;

access_log /var/log/nginx/pypi.access.log;

# try serving static files directly
location ~ /\+f/ {
error_page 418 = @pypi_backend;
if ($request_method !~ (GET)|(HEAD)) {
return 418;
}

expires max;
try_files /+files$uri @pypi_backend;
}

# try serving docs directly
location ~ /\+doc/ {
try_files $uri @pypi_backend;
}

location / {
error_page 418 = @pypi_backend;
return 418;
}

location @pypi_backend {
proxy_pass http://pypi-backend; # Using the upstream definition
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-outside-url $scheme://$host:$server_port;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
}
}
}

使用此配置的 Nginx 和在 http://localhost:8080 上运行的 devpi,您应该能够访问 https://localhost 或使用您的机器适当的 DNS https://example.co.uk。请求将是:

client (HTTPS) > Nginx (HTTP) > devpi (HTTP) > Nginx (HTTPS) > client

这也意味着您将需要确保 Nginx 正在运行,因为 devpi start 不会知道更多。您至少应该看到一个 Nginx 欢迎页面。

关于ssl - 如何使用 https 服务 devpi?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56050912/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com