{"id":2384,"date":"2018-05-11T19:02:16","date_gmt":"2018-05-11T13:32:16","guid":{"rendered":"https:\/\/pheonixsolutions.com\/blog\/?p=2384"},"modified":"2026-09-28T20:18:37","modified_gmt":"2026-09-28T14:48:37","slug":"configure-uwsgi-with-nginx-for-django-applications","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/configure-uwsgi-with-nginx-for-django-applications\/","title":{"rendered":"Configure uwsgi with nginx for Django applications"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>Post Date: <\/strong>May 11, 2018<strong><br>Last Updated: <\/strong>September 22, 2026<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Django is a popular Python web framework used to develop web applications. For production deployments, Django applications are commonly served through an application server such as <strong>uwsgi<\/strong>, with <strong>Nginx<\/strong> acting as the front-end web server.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Nginx handles incoming HTTP requests and forwards application requests to uWSGI through a Unix socket. uWSGI then communicates with the Django application and returns the response to Nginx.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this article, we will explain how to configure <strong>uwsgi with Nginx for a Django application<\/strong> on <strong>RHEL 7.4<\/strong>.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\"><strong>Note:<\/strong> This article uses Python 2.7 and a legacy RHEL 7.4 deployment approach from 2018. Python 2.7 is end-of-life, and modern Django applications should use a supported Python version and a current deployment approach.<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Before configuring uwsgi and Nginx, make sure the following are available:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>RHEL 7.4 or a compatible CentOS 7 system.<\/li>\n\n\n\n<li>Root or sudo access.<\/li>\n\n\n\n<li>Python 2.7.<\/li>\n\n\n\n<li>pip.<\/li>\n\n\n\n<li>Nginx.<\/li>\n\n\n\n<li>Django.<\/li>\n\n\n\n<li>uWSGI.<\/li>\n\n\n\n<li>A configured Django application.<\/li>\n\n\n\n<li>A domain name pointing to the server.<\/li>\n<\/ul>\n\n\n\n<h1 class=\"wp-block-heading\">Implementation<\/h1>\n\n\n\n<h2 class=\"wp-block-heading\">Step 1: Update the Server<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Update the installed packages:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">yum -y update<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Install the required development packages:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">yum install gcc openssl-devel bzip2-devel python-devel python-setuptools python-pip<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Step 2: Install Python 2.7<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Download the required Python version:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">cd \/usr\/src\n\nwget https:\/\/www.python.org\/ftp\/python\/2.7.13\/Python-2.7.13.tar.xz<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Extract the downloaded archive:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">tar -xvf Python-2.7.13.tar.xz<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Navigate to the extracted directory:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">cd Python-2.7.13\/<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Configure Python:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">.\/configure<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Compile and install it:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">make install<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Verify the installed version:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">python2.7 -V<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Expected output:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Python 2.7.13<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Step 3: Install and Configure Nginx<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Install Nginx using yum:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">yum install nginx<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Enable Nginx to start automatically after a server reboot:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">systemctl enable nginx<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Start the Nginx service:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">systemctl start nginx<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Check the service status:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">systemctl status nginx<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If a firewall is enabled, make sure HTTP and HTTPS traffic is allowed on ports:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">80\n443<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You can verify Nginx by accessing:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">http:\/\/your_server_ip_address\/<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The default Nginx welcome page should be displayed.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 4: Install Django and uwsgi<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Install Django using pip:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">pip install django<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Install uwsgi:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">pip install uwsgi<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Verify the uwsgi installation:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">uwsgi --version<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Step 5: Configure the Django Website<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In this example, the Django application is hosted at:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/var\/www\/pheonix\/<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">and the domain is:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">web.pheonixsolutions.com<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Create an Nginx configuration file:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">vi \/etc\/nginx\/conf.d\/web.pheonixsolutions.com.conf<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Add the following configuration:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">upstream web_pheonix {\n\n    server unix:\/\/\/var\/www\/pheonix\/web_pheonix.sock;\n\n}\n\nserver {\n\n    listen 80;\n\n    server_name web.pheonixsolutions.com;\n\n    charset utf-8;\n\n    client_max_body_size 75M;\n\n    location \/media {\n        alias \/var\/www\/pheonix\/media;\n    }\n\n    location \/static {\n        alias \/var\/www\/pheonix\/static;\n    }\n\n    location \/ {\n\n        uwsgi_pass web_pheonix;\n\n        include \/etc\/nginx\/uwsgi_params;\n\n    }\n\n}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Configuration Explanation<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>upstream<\/code> block defines the uwsgi application server:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">upstream web_pheonix {\n    server unix:\/\/\/var\/www\/pheonix\/web_pheonix.sock;\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The Unix socket provides communication between Nginx and uWSGI.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>server<\/code> block defines the domain:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">server_name web.pheonixsolutions.com;<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Static and media files are served directly by Nginx:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">location \/media {\n    alias \/var\/www\/pheonix\/media;\n}\n\nlocation \/static {\n    alias \/var\/www\/pheonix\/static;\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Other requests are forwarded to uWSGI:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">location \/ {\n    uwsgi_pass web_pheonix;\n    include \/etc\/nginx\/uwsgi_params;\n}<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Step 6: Configure <code>uwsgi_params<\/code><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Open the Nginx uWSGI parameters file:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">vi \/etc\/nginx\/uwsgi_params<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Add the following parameters:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">uwsgi_param QUERY_STRING       $query_string;\nuwsgi_param REQUEST_METHOD     $request_method;\nuwsgi_param CONTENT_TYPE       $content_type;\nuwsgi_param CONTENT_LENGTH     $content_length;\nuwsgi_param REQUEST_URI        $request_uri;\nuwsgi_param PATH_INFO          $document_uri;\nuwsgi_param DOCUMENT_ROOT      $document_root;\nuwsgi_param SERVER_PROTOCOL    $server_protocol;\nuwsgi_param REQUEST_SCHEME     $scheme;\nuwsgi_param HTTPS              $https if_not_empty;\nuwsgi_param REMOTE_ADDR        $remote_addr;\nuwsgi_param REMOTE_PORT        $remote_port;\nuwsgi_param SERVER_PORT        $server_port;\nuwsgi_param SERVER_NAME        $server_name;<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">These parameters allow Nginx to pass the required request information to the uWSGI application server.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For additional information, refer to the <a href=\"https:\/\/uwsgi-docs.readthedocs.io\/en\/latest\/tutorials\/Django_and_nginx.html?utm_source=chatgpt.com\" target=\"_blank\" rel=\"noreferrer noopener\">uwsgi Django and Nginx documentation<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 7: Create the uwsgi Configuration<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Create a uwsgi configuration file:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">vi web_pheonix.ini<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Add:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">[uwsgi]\n\n# Django-related settings\n\n# Base directory\nchdir = \/var\/www\/pheonix\/\n\n# Django's WSGI file\nmodule = pheonix.wsgi\n\n# Master process\nmaster = true\n\n# Number of worker processes\nprocesses = 10\n\n# Unix socket\nsocket = \/var\/www\/pheonix\/web_pheonix.sock\n\n# Socket permissions\nchmod-socket = 666\n\n# Clear environment on exit\nvacuum = true\n\n# Optional settings\n# max-requests = 5000\n# limit-as = 128\n# daemonize = \/var\/log\/uwsgi-emperor.log<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Important Settings<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>chdir<\/code> option specifies the Django project directory:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">chdir = \/var\/www\/pheonix\/<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>module<\/code> option specifies the Django WSGI module:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">module = pheonix.wsgi<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The number of uwsgi worker processes is configured using:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">processes = 10<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The socket must match the socket configured in Nginx:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">socket = \/var\/www\/pheonix\/web_pheonix.sock<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Step 8: Test the uwsgi Configuration<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Run uWSGI using the configuration file:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">uwsgi --ini web_pheonix.ini<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This allows you to verify whether uWSGI can successfully start the Django application.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If there are configuration or application errors, resolve them before proceeding.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 9: Configure uWSGI Emperor Mode<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">uwsgi Emperor mode allows a central uwsgi process to monitor a directory containing application configuration files.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Create the vassals directory:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">mkdir -p \/etc\/uwsgi\/vassals<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Copy or place the Django application&#8217;s uWSGI configuration file inside the vassals directory.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">cp web_pheonix.ini \/etc\/uwsgi\/vassals\/<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Start uwsgi in Emperor mode:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">uwsgi --emperor \/etc\/uwsgi\/vassals<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The Emperor process monitors the configuration files in the vassals directory and manages individual uwsgi application instances.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When a vassal configuration changes, the Emperor can restart the corresponding application instance.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 10: Verify the Website<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Once Nginx and uwsgi are running, access:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">http:\/\/web.pheonixsolutions.com<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Nginx receives the request and forwards it to uwsgi through:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/var\/www\/pheonix\/web_pheonix.sock<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">uWSGI then passes the request to the Django application.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 11: Start uwsgi Automatically After Reboot<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Create a startup script:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">vi \/opt\/scripts\/uwsgi_restart.sh<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Add:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#!\/bin\/bash\n\n\/usr\/local\/bin\/uwsgi --emperor \/etc\/uwsgi\/vassals<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Make the script executable:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">chmod +x \/opt\/scripts\/uwsgi_restart.sh<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Add the script to <code>\/etc\/rc.local<\/code>:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">vi \/etc\/rc.local<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Add:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/opt\/scripts\/uwsgi_restart.sh<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This allows the uwsgi Emperor process to start when the server boots.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\"><strong>Note:<\/strong> On RHEL 7, systemd is the preferred service-management mechanism. The <code>rc.local<\/code> method shown above reflects the original legacy deployment approach.<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Configuring Nginx with uWSGI provides a structured way to deploy Django applications. In this setup, Nginx acts as the front-end web server, while uWSGI handles communication with the Django application through a Unix socket.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The overall workflow is:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Install Python and required dependencies.<\/li>\n\n\n\n<li>Install Nginx.<\/li>\n\n\n\n<li>Install Django and uwsgi.<\/li>\n\n\n\n<li>Configure Nginx for the Django domain.<\/li>\n\n\n\n<li>Configure the uwsgi parameters.<\/li>\n\n\n\n<li>Create the uwsgi application configuration.<\/li>\n\n\n\n<li>Test the uwsgi application.<\/li>\n\n\n\n<li>Configure uwsgi Emperor mode.<\/li>\n\n\n\n<li>Configure automatic startup.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">This setup allows Nginx to efficiently serve static content while forwarding dynamic Django requests to uwsgi.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\"><strong>Legacy deployment note:<\/strong> Python 2.7 and RHEL 7.4 are no longer current platforms. For a new deployment, use a supported Python version, supported Django release, and a modern service-management approach such as systemd.<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\">FAQ<\/h2>\n\n\n\n<h4 class=\"wp-block-heading\">1. What is uwsgi?<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">uwsgi is an application server that can run Python web applications and communicate with web servers such as Nginx using protocols such as the uwsgi protocol.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">2. Why use Nginx with uwsgi?<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Nginx can handle incoming HTTP requests, static files, client connections, and other web-server responsibilities while forwarding dynamic application requests to uwsgi.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">3. What is the purpose of the Unix socket?<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">The Unix socket provides communication between Nginx and uwsgi on the same server.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this example:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/var\/www\/pheonix\/web_pheonix.sock<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The same socket must be configured in both Nginx and uWSGI.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">4. What is uwsgi Emperor mode?<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Emperor mode allows uwsgi to manage multiple application instances, called vassals, from a central configuration directory.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this example:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/etc\/uwsgi\/vassals<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Related Article<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/pheonixsolutions.com\/blog\/setting-up-django-and-your-web-server-with-uwsgi-and-nginx-on-ubuntu\/?utm_source=chatgpt.com\" target=\"_blank\" rel=\"noreferrer noopener\">Setting up Django and your Web Server with uWSGI and Nginx on Ubuntu<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Talk to our experts<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Looking for the right technology solution for your business? Our team of experts can help you with development, cloud, DevOps, design, and a wide range of other technology needs. Get in touch with our team <a target=\"_blank\" rel=\"noreferrer noopener\" href=\"https:\/\/pheonixsolutions.com\/contact?utm_source=chatgpt.com\">here<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Post Date: May 11, 2018Last Updated: September 22, 2026 Introduction Django is a popular Python web framework used to develop [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1022],"tags":[261,407],"class_list":["post-2384","post","type-post","status-publish","format-standard","hentry","category-web-architecture","tag-linux","tag-uwsgi","psol-cat-web-architecture"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/phn2x7-Cs","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/2384","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=2384"}],"version-history":[{"count":3,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/2384\/revisions"}],"predecessor-version":[{"id":11982,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/2384\/revisions\/11982"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=2384"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=2384"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=2384"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}