I have a server(Ubuntu 16.04) and a user called coxier
.
I configure Nginx to Proxy Requests. I create a file etc/nginx/sites-available/myproject
.
server { listen 80; server_name 101.200.36.xx; location / { include uwsgi_params; uwsgi_pass unix:/home/coxier/iemoji/server/iemoji.sock; } }
In this flask project, server receive request and then generate a .gif
file for this request.
At first I directly I use flask#send_file
to send gif file about 1MB, however speed is very slow.
So I decide to optimize the request.
- Receive http request and generate gif file.
- Return url of the generated gif file to user.
- User access gif file by url.
I have a question. How can I generate url of the generated gif?
I have tried like below.
server { listen 80; server_name 101.200.36.xx; root /home/coxier/iemoji/server/output; location / { include uwsgi_params; uwsgi_pass unix:/home/coxier/iemoji/server/iemoji.sock; } }
For example, I want to access /home/coxier/iemoji/server/output/a3dfa3eb21daffc7085f71630cbd169e/output.gif
.
Then I return http://101.200.36.xx/a3dfa3eb21daffc7085f71630cbd169e/output.gif
to user.
However nginx returns 404 Not Found.
Advertisement
Answer
From https://docs.nginx.com/nginx/admin-guide/web-server/serving-static-content/ , I find solution.
server { listen 80; server_name 101.200.36.xx; location / { include uwsgi_params; uwsgi_pass unix:/home/coxier/iemoji/server/iemoji.sock; } location ~ .(gif) { root /home/coxier/iemoji/server/output; sendfile on; sendfile_max_chunk 1m; } }
You should redefine root in location
block.
Then you can generate url like this:
http://101.200.36.xx/a3dfa3eb21daffc7085f71630cbd169e/output.gif.