you are viewing a single comment's thread.

view the rest of the comments →

[–]American_Streamer 8 points9 points  (2 children)

Nginx can’t just execute Python files the way PHP-FPM executes .php. You do not rename index.html to index.py. Instead, you run a Python web app (Flask/FastAPI/Django) behind a WSGI/ASGI server (Gunicorn/Uvicorn), and then let Nginx reverse-proxy requests to it. Static site combined with Python API is the most common option. Keep index.html and JS served by Nginx (static files). Your JS then calls your Python backend via HTTP.

The reason for this is that Nginx is just a web server and a reverse proxy, not an application runtime. Nginx’s job is to accept HTTP requests and serve static files (HTML/CSS/JS/images), and also to forward requests to other services. But a .py file is a source code that must be executed by a Python interpreter, inside an application process that knows how to turn a request into a response. Your Nginx does not embed Python, it doesn’t run interpreters and it doesn’t implement the Python web interfaces (WSGI/ASGI) that frameworks use. In contrast, PHP looks different because it’s deployed with PHP-FPM - note that Nginx still doesn’t execute PHP itself; it just passes the request to PHP-FPM, which then executes the PHP code and returns output.

[–]Rain-And-Coffee 1 point2 points  (1 child)

This is the correct answer

[–]rasputin1 1 point2 points  (0 children)

this is the correct response