Forums

Custom nginx configuration

I have an app hosted on your service. It is a basic REST api which serves HTTP and socket requests. I also have a static folder in this app which is used for saving images and videos on the system.

I have read the docs on how to set up a static path in my application, however that does not really serve my purpose. The application is built with the intention to minimize requests to the REST Api, and instead direct the traffic to an NGINX server which will handle all the static file serving. My Nginx config file has 3 routes built into it. One of them is handling all requests on /api/ which directs all the traffic to my REST Api. The other route is /static/ directs all the requests the static file server (/usr/share/nginx/html/app/ on my local or /home/me/mysite/static/ on your remote). The third route is just / which serves up the static build (result folder of npm build on my react application).

I presume that on your server, the configuration is done a bit differently - when user hits / route they are pointed at the REST api and the REST api handles all the routing and therefore the REST api should also handle serving of static files. This will not work for me as it is expected for a lot of files to be requested from the server and we do not want to put that traffic through our Rest API, we want NGINX to handle that traffic.

Ideally I would ask for full access to nginx, its config files and its root directory but if that is not an option, I would request changes by an admin user to my virtual server as so:

location /static/ {
    sendfile on;
    autoindex on; 
    root /home/me/mysite/static/;
}

location /api/ {
   requests to my api.
}

Thank you in advance.

We are not able to provide you with access to the Nginx configuration.

If you set static mapping in your web app, requests to the mapped routes won't hit your web app. Did you look at https://help.pythonanywhere.com/pages/StaticFiles?