Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

184
Visualizações
ssl con django gunicorn y nginx

Actualmente estoy trabajando en la implementación de mi proyecto a través de https, sin embargo, tengo algunos problemas. Lo tengo funcionando con http pero cuando intento incorporar el ssl se rompe. Creo que estoy configurando mal el cliente upstream de gunicorn en mi bloque nginx, pero no estoy seguro. ¿Podría el problema estar en el enlace de Unix en mi archivo de servicio gunicorn? Soy muy nuevo en gunicorn, así que estoy un poco perdido.

Aquí está mi configuración a continuación.

gunicornio:

 [Unit] Description=gunicorn daemon After=network.target [Service] Environment=PYTHONHASHSEED=random User=USER Group=www-data WorkingDirectory=/path/to/project ExecStart=/path/to/project/project_env/bin/gunicorn --workers 3 --bind unix:/path/to/project/project.sock project.wsgi:application [Install] WantedBy=multi-user.target

Nginx (en funcionamiento-http):

 server { listen 80 default_server; listen [::]:80 default_server; server_name server_domain; location = /favicon.ico { access_log off; log_not_found off; } location /static/ { root /path/to/project; } location / { include proxy_params; proxy_pass http://unix:/path/to/project/project.sock; } }

Nginx (https):

 upstream server_prod { server unix:/path/to/project/project.sock fail_timeout=0; } server { listen 80 default_server; listen [::]:80 default_server; server_name server_domain; } server { server_name server_domain; listen 443; ssl on; ssl_certificate /etc/ssl/server_domain.crt; ssl_certificate_key /etc/ssl/server_domain.key; location /static/ { root /path/to/project; } location / { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto https; proxy_set_header Host $http_host; proxy_redirect off; if (!-f $request_filename) { proxy_pass http://server_prod; break; } } }
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Su archivo de unidad gunicorn systemd parece estar bien. Su nginx generalmente también está bien. Ha publicado muy poca información para obtener un diagnóstico adecuado. Supongo que te falta pasar el encabezado X-Forwarded-Proto a gunicorn, pero podría ser otra cosa. Aquí hay un archivo de configuración de nginx que funciona para mí:

 upstream gunicorn{ # fail_timeout=0 means we always retry an upstream even if it failed # to return a good HTTP response (in case the Unicorn master nukes a # single worker for timing out). # for UNIX domain socket setups: server unix:/path/to/project/project.sock fail_timeout=0; # for TCP setups, point these to your backend servers # server 127.0.0.1:9000 fail_timeout=0; } server { listen 80; listen 443 ssl http2; server_name server_domain; ssl_certificate /etc/ssl/server_domain.crt; ssl_certificate_key /etc/ssl/server_domain.key; # path for static files root /path/to/collectstatic/dir; location / { # checks for static file, if not found proxy to app try_files $uri @proxy_to_app; } location @proxy_to_app { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; # When Nginx is handling SSL it is helpful to pass the protocol information # to Gunicorn. Many web frameworks use this information to generate URLs. # Without this information, the application may mistakenly generate http # URLs in https responses, leading to mixed content warnings or broken # applications. In this case, configure Nginx to pass an appropriate header: proxy_set_header X-Forwarded-Proto $scheme; # pass the Host: header from the client right along so redirects # can be set properly within the Rack application proxy_set_header Host $http_host; # we don't want nginx trying to do something clever with # redirects, we set the Host: header above already. proxy_redirect off; # Try to serve static files from nginx, no point in making an # *application* server like Unicorn/Rainbows! serve static files. proxy_pass http://gunicorn; } }
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda