Scale up as you grow — whether you're running one virtual machine or ten thousand.

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.

This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
This comment has been deleted
Hello Kathleen/Justin. Thank you for the great how-to. You might want to include that the default file in /etc/nginx/sites-enabled/ needs to be removed or commented out.
Hello guys, first, thank you for this awesome tutorial! Everything is working magically. However, I have one minor request regarding static files and templates (html pages) within the Flask application. I am able to serve my application on Nginx, but so far I was not able to find a way to serve my app in full power: at the moment I can access the index webpage, but I have also css files and other locations (host:port/token, for example) which are not found, or application lacks design (which is specified in css files). Is there a way to reconfigure nginx additionally to use these files in the app as well? It does run perfectly when using gunicorn to start the app, but in my situation it seems as if Nginx has to be additionally filled with some extra configuration.
p.s. my .html files are loading css files the following way (for example):
<link rel="stylesheet" href="{{ url_for('static', filename='css/global.css') }}" />
There´s some important notes here, that should be added to the tutorial, while many will struggle with this. Look at the provided answer here: https://stackoverflow.com/questions/39919053/django-gunicorn-sock-file-not-created-by-wsgi#_=_
Someone Please Help. I am facing a weird Problem.I have don everything right upto Step 4.Everything is so fine and good.
But in the** Step 5 — Configuring Nginx to Proxy Requests** i might be doing something wrong that i can’t connect to server with domain via Browser.
Here is my /etc/nginx/sites-available/myproject nginx scrpt:
server {
listen 80;
server_name linearaxon.com www.linearaxon.com;
location / {
include proxy_params;
proxy_pass http://unix:/root/linearaxon/linearaxon.sock:/;
}
}
After writting this script i did all the commands like:
sudo ln -s /etc/nginx/sites-available/myproject /etc/nginx/sites-enabled
sudo nginx -t
sudo systemctl restart nginx
sudo ufw delete allow 5000
sudo ufw allow 'Nginx Full'
Now if i ping ** linearaxon.com** then it correctly points to my ip which it should.
Then when i type my ip in the browser it shows me the welcome page of Nginx.Which actually caused by default in sites-enabled pointing to var/www/default-nginx.html or so.
But when i type my domain name linearaxon.com.** It shows Nginx Welcome Page.**
here is my nginx.conf
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
#mail {
# # See sample authentication script at:
# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
# # auth_http localhost/auth.php;
# # pop3_capabilities "TOP" "USER";
# # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
# server {
# listen localhost:110;
# protocol pop3;
# proxy on;
# }
#
# server {
# listen localhost:143;
# protocol imap;
# proxy on;
# }
#}
When i delete default from both sites-available and sites-enabled then it shows me 502 Bad GateWay
Please someone help me.Please.What is happening with me?
In step 4 /etc/systemd/system/myproject.service, give your user name carefully. If you are logging as root then give root and you have to also change the user from www-data to root in /etc/nginx/nginx.conf. give project location always in /home/.
This was terrific. But please emphasize that the full tutorial must be done using a single non-root user with sudo permissions. I was mix and matching and the system kept breaking. I lost hours. Thanks .
Great guide, thanks for posting it. I’m running into an issue with the system service.
sudo systemctl status myproject
returns
gunicorn: error: unrecognized arguments: wsgi:app
Which is odd because the same command worked fine in the previous step.
FYI I am using root user.
Hi, great guide, super helpful and straightforward. I have been going in circles trying to solve a problem and hopefully I can get some help here. I have this working running on my local machine following the guide. However when I am trying to implement on the actual server with the same config I am running into an issue on proxying requests back to the gunicorn server. I am able to serve static content from Nginx with no problem. When I make a web service call from the static content back to Nginx, it should be proxied back to the gunicorn server.
For example when I try to make the call ‘http://example.com/rest/webService’, I would expect Nginx to pass anything starting with /rest/ back to gunicorn. The error below is all I can see in the error logs about what is happening:
2019/01/18 12:48:18 [error] 2930#2930: *18 open() “/var/www/html/rest/webService” failed (2: No such file or directory), client: ip_address, server: example.com, request: “GET /rest/webService HTTP/1.1”, host: “example.com”, referrer: “http://example.com/”
Here is the setup for python_app:
server {
listen 80;
server_name example.com www.example.com;
root /var/www/html;
index index.html;
location ^/rest/(.*)$ {
include proxy_params;
proxy_pass http://unix:/home/username/python_app/python_app.sock;
}
}
The only change to my nginx.conf file was to change ‘include /etc/nginx/sites-enabled/*’ to ‘include /etc/nginx/sites-enabled/python_app’.
Please let me know if you have any ideas at all on what I may be missing! Thanks!
Thanks for the tutorial, it works great, but I have a problem. When I use the following code:
from flask import request
request.remote_addr
I was expecting that the client’s IP will be shown, but instead an empty string appears. I used this tutorial for local development and there was no problem, but now DigitalOcean does not work.