Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

955
Views
Flask + Gunicorn + Nginx, error 404 al usar proxy_pass desde un bloque de ubicación no raíz

Me gustaría recibir información del usuario, ejecutar algunas líneas de Python y mostrar los resultados en la web.

Tengo un dominio que apunta a un servidor en DigitalOcean y estoy siguiendo este tutorial: https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-gunicorn-and-nginx-on -ubuntu-18-04

Pude completar el tutorial y funciona, sin embargo, por supuesto, me gustaría que mi sitio no se anule por completo con la frase "¡Hola!". Me gustaría mostrar los resultados en una ubicación que no sea raíz, como https://example.com/myproject/ .

El dominio que tengo ya ha sido asegurado usando Let's Encrypt & CertBot.

Estoy usando un solo archivo de configuración nginx llamado predeterminado: el resto del tutorial lo seguí exactamente. El problema parece estar en la directiva proxy_pass. Cuando lo muevo al bloque / ubicación, funciona y mi página de índice se anula con "¡Hola!". Cuando muevo proxy_params y proxy_pass a un bloque de ubicación /myproject/, aparece un error 404. Probé un puñado de cosas y traté de comprender mejor los bloques de ubicación, pero fue en vano.

Aquí está el archivo de configuración de Nginx:

 # Default server configuration # server { root /var/www/html; # Add index.php to the list if you are using PHP index index.html index.htm index.php; server_name example.com www.example.com; location / { # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. try_files $uri $uri/ =404; } location /myproject/ { include proxy_params; proxy_pass http://unix:/home/jackson/myproject/myproject.sock; } # pass the PHP scripts to FastCGI server location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php7.0-fpm.sock; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one location ~ /\.ht { deny all; } listen [::]:443 ssl ipv6only=on; # managed by Certbot listen 443 ssl; # managed by Certbot ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot }

Cualquier ayuda sería muy apreciada. ¡Gracias!

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Necesitaba cambiar el decorador @app.route en el archivo .py al correcto directamente, y creo que es crucial especificar los métodos GET y POST .

 from flask import Flask app = Flask(__name__) @app.route("/myproject/", methods=['GET','POST']) def hello(): return "<h1 style='color:blue'>Hello There!</h1>" if __name__ == "__main__": app.run(host='0.0.0.0')
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!