{"id":21926739,"url":"https://github.com/gigibean/django-nginx-server","last_synced_at":"2026-04-13T13:02:11.559Z","repository":{"id":118322208,"uuid":"293664185","full_name":"gigibean/django-nginx-server","owner":"gigibean","description":"Integrating django app with nginx : centos-6.9 python-3.5.1 nginx-1.18.0 django-2.2.16 uwsgi-2.0.19.1 mysql-15.1 MariaDB-10.3.24 pip-20.2.2","archived":false,"fork":false,"pushed_at":"2020-09-10T08:54:31.000Z","size":20,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-22T12:14:08.070Z","etag":null,"topics":["centos6","django","mariadb","mysql","nginx","python35","uwsgi","uwsgi-nginx"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gigibean.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-09-08T00:53:27.000Z","updated_at":"2023-03-04T02:35:29.000Z","dependencies_parsed_at":null,"dependency_job_id":"6ea60b3c-c237-4599-9c1b-196e991e0805","html_url":"https://github.com/gigibean/django-nginx-server","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/gigibean/django-nginx-server","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gigibean%2Fdjango-nginx-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gigibean%2Fdjango-nginx-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gigibean%2Fdjango-nginx-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gigibean%2Fdjango-nginx-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gigibean","download_url":"https://codeload.github.com/gigibean/django-nginx-server/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gigibean%2Fdjango-nginx-server/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31753551,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-13T09:16:15.125Z","status":"ssl_error","status_checked_at":"2026-04-13T09:16:05.023Z","response_time":93,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["centos6","django","mariadb","mysql","nginx","python35","uwsgi","uwsgi-nginx"],"created_at":"2024-11-28T22:11:05.131Z","updated_at":"2026-04-13T13:02:11.539Z","avatar_url":"https://github.com/gigibean.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# django nginx server\nIntegrating django app with nginx\n\n```shell\nyum update \u0026\u0026 yum update wget\n```\n\t\t\n## 1. Install Python35\t\n\n```shell\n$ yum install zlib-devel-y\n$ yum install xz\n$ yum install openssl openssl-devel-y\n$ wget https://www.python.org/ftp/python/3.5.1/Python-3.5.1.tar.xz\n$ xz -d Python-3.5.1.tar.xz\n$ tar -xvf Python-3.5.1.tar\n$ cd Python-3.5.1.tar.xz\n$ ./configure --prefix=/usr/local --enable-shared LDFLAGS=\"-Wl,-rpath /usr/local/lib\"\n$ make \u0026\u0026 make altinstall\n$ python3.5 --version\n```\n\t\t\n## 2. Install pip3\t\t\n\t\t\n```shell\n$ curl -k -O https://bootstrap.pypa.io/get-pip.py\n$ python3.5 get-pip.py\n```\n\t\t\n## 3. Install django\t\t\n\t\t\n```shell\n$ pip3 install Django==2.2.16\n$ python3.5\n\u003e import django\n\u003e print(django.get_version()) \n```\n\t\t\n## 4. Install MariaDB\t\t\n\t\t\n```shell\n$ /etc/yum.repo.d/\n$ vi MariaDB.repo\n\n# You can get this file the command: \n# $ curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash\n# And this command make a file named 'mariadb.repo' in /etc/yum.repo.d/\n# So Change this file name 'mariadb.repo' to 'MariaDB.repo' if you need \n# But this command allowed to download version 10.5 that is not supported in my os version\n# Otherwise, you enter the url: \n# 'https://downloads.mariadb.org/mariadb/repositories/#distro=CentOS\u0026distro_release=centos6-amd64--centos6\u0026mirror=harukasan\u0026version=10.3'\n# and choose a version that fits your OS version and specification\n\n# MariaDB 10.3 CentOS repository list - created 2020-09-04 02:11 UTC\n# http://downloads.mariadb.org/mariadb/repositories/\n[mariadb]\nname = MariaDB\nbaseurl = http://yum.mariadb.org/10.3/centos6-amd64\ngpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB\ngpgcheck=1\n\n[mariadb-maxscale]\n# To use the latest stable release of MaxScale, use \"latest\" as the version\n# To use the latest beta (or stable if no current beta) release of MaxScale, use \"beta\" as the version\nname = MariaDB MaxScale\nbaseurl = https://downloads.mariadb.com/MaxScale/2.4/centos/$releasever/$basearch\ngpgkey = file:///etc/pki/rpm-gpg/MariaDB-MaxScale-GPG-KEY\ngpgcheck = 1\nenabled = 1\n\n[mariadb-tools]\nname = MariaDB Tools\nbaseurl = https://downloads.mariadb.com/Tools/rhel/$releasever/$basearch\ngpgkey = file:///etc/pki/rpm-gpg/MariaDB-Enterprise-GPG-KEY\ngpgcheck = 1\nenabled = 1\n# You have to write this repository before you install MariaDB\n# This repo is about MariaDB's version and tools\n\n# for [Errono 14]\n$ mv mariadb.repo mariadb.repo.original\n$ yum clean all\n$ rm -rf /ver/cache/yum/*\n\n# Delete mysql-server to avoid crash\n$ rpm -qa | grep -i '^mysql-'\n# If you find 'mysql-sever-(numbers)'\n$ rpm --nodeps -ev mysql-server-(numbers)\n\n$ yum install MariaDB-server\n$ yum install mysql\n\n$ /etc/init.d/mysql start\n$ /usr/bin/mysqladmin -u root password 'passwd'\n$ netstat -anp | grep 3306\n# check mysql service\n$ mysql -u root -p\n\u003e Enter password: \n# Set auto start on boot: this command is different from centos7\n$ chkconfig mysql on\n$ chkconfig --list mysql\n# mysql           0:off   1:off   2:on    3:on    4:on    5:on    6:off\n$ service mysql status\n# SUCCESS! MariaDB running (17356)\n$ service mysql enable\n$ mysql_secure_installation\n\u003e Enter current password for root (enter for none):\n\u003e OK, successfully used password, moving on...\n\n\u003e Setting the root password ensures that nobody can log into the MariaDB\n\u003e root user without the proper authorisation.\n\n\u003e You already have a root password set, so you can safely answer 'n'.\n\n\u003e Change the root password? [Y/n] n\n\u003e Remove anonymous users? [Y/n] Y\n\u003e Disallow root login remotely? [Y/n] Y\n\u003e Remove test database and access to it? [Y/n] Y\n\u003e Reload privilege tables now? [Y/n] Y\n```\n\t\t\n## 5. Install mysqlclient\t\t\n\t\t\n```shell\n$ yum search python35 | grep devel\n# Download python35 + devel\n$ yum install  rh-python35-python-devel.x86_64  rh-python35-scldevel.x86_64\n# I found that the problem is that mysqlclient requires mysql-devel packages, which is different from mariadb-devel. Don't install mariadb-devel!\n# So you need to:\n# Remove MariaDB-devel which is installed when we install MariaDB-server\n$ yum list installed | grep mariadb\n$ sudo yum erase MariaDB-devel.x84_64\n\n# Add MySQL repository in yum\n# Go to https://dev.mysql.com/downloads/repo/yum/ and select the RPM file for your CentOS \n# (for me, I choose \"Red Hat Enterprise Linux 6 / Oracle Linux 6 (Architecture Independent), RPM Package\"\n# Go to you terminal and type:\n$ wget https://dev.mysql.com/get/mysql80-community-release-el6-3.noarch.rpm\n$ sudo rpm -Uvh mysql80-community-release-el6-3.noarch.rpm\n$ sudo yum install mysql-community-devel.x86_64\n$ sudo pip install mysqlclient\n```\n\t\t\n## 6. Set mysql\t\t\n\t\t\n```shell\n$ mysql -u root -p\n\u003e Enter password: \n\u003e create database db_name\n\u003e grant all privileges on db_name.* to user_name@localhost identified by 'password';\n\u003e grant all privileges on db_name.* to user_name@'%' identified by 'password';\n\u003e flush privileges;\n\u003e exit\n```\n\t\t\n## 7. Install nginx\t\t\n\t\t\n```shell\n$ vi /etc/yum.repo.d/nginx.repo\n[nginx]\nname=nginx repo\nbaseurl=http://nginx.org/packages/centos/\\$releasever/\\$basearch/\ngpgcheck=1\nenabled=1\ngpgkey=https://nginx.org/keys/nginx_signing.key\n\n$ yum info nginx\n$ yum install nginx\n# Set auto start on boot: this command is different from centos7\n$ chkconfig nginx on #systemctl enabl nginx \n$ service nginx restart # systemctl restart nginx\n```\n\t\t\n## 8. Install uwsgi\t\t\t\n\t\t\n```shell\n$ pip3 install uwsgi\n```\n\t\t\n## 9. Set user\u0026group\t\t\t\t\n\t\t\t\n```shell\n$ groupadd group_name\n$ grep group_name /etc/group\n\n$ useradd -g group_name -s /sbin/nologin -p 'password' user_name\n$ echo 'password' | passwd --stdin user_name\n$ cat /etc/passwd\n```\n\t\t\t\n## 10. make django project\t\t\n\t\t\n```shell\n$ cd /home/user_name\n$ mkdir main_project\n$ cd main_proejct\n$ pip3 install virtualenv\n$ virtualenv myvenv\n$ source myvenv/bin/activate\n$ mkdir dir1 dir2\n$ cd dir1\n$ django-admin.py startproejct sample\n$ cd sample/sample\n$ vi settings.py\nALLOWED_HOSTS = ['your_domain', 'your_ip']\nDATABASES = {\n    'default': {\n        'ENGINE': 'django.db.backends.mysql',\n        'NAME': 'db_name',\n        'USER': 'user_name',\n        'PASSWORD': 'password',\n        'HOST': '',\n        'PORT': '',\n    }\n}\nSTATIC_URL = '/static/'\nSTATIC_ROOT = \"/var/www/your_domain/static/\"\n\nMEDIA_URL = '/media/'\nMEDIA_ROOT = \"/var/www/you_domain/media/\"\n```\n\t\t\n## 11. Set nginx\t\t\n\t\n```shell\n$ cd /etc/nginx/conf.d/nginx.conf\n$ mv default.conf default.conf.ogirinal\n$ cp /etc/nginx/uwsgi_params /home/user_name/main_dir/dir1/project_dir/uwsgi_params\n$ vi naignx.conf\nupstream django {\n   server unix:/home/user_dir/main_dir/dir2/uwsgi.sock;\n}\nserver {\n        listen 80;\n        server_name your_domain_or_ip;\n        charset utf-8;\n        # location = /favicon.ico { access_log off; log_not_found off; }\n        location /static/ {\n                alias /var/www/your_domain_or_ip/static/;\n\t\t# alias /your_project_folder/static/;\n        }\n        location / {\n            include /home/user_dir/main_dir/dir1/proejct_dir/uwsgi_params;\n            uwsgi_pass      django;\n        }\n}\n```\n\t\t\n## 12. Set uwsgi\t\t\n\t\t\nThere are two modes in `uwsgi`: Emperor mode and Default(General) mode\t  \n\nThe Emperor mode is to run server as a whole computer is one server   \n\nContrary, The Default(General) mode is to run server as django applications are each server\t \t\n\nThe uWSGI program(both modes) also supports the UDS method\t\t \t\n\n\t\nEmperor mode\t\t\n-------------\t\t\n\t\n```\n$ /etc/re.d/init.d/uwsgi\n$ mkdir -p /etc/uwsgi/vassals\n$ sudo vi etc/uwsgi/vassals/uwsgi.ini\n[uwsgi]\nuid = user_name\nbase = /home/%(uid)/main_dir\nroot /home/%(uid)/main_dir/dir1/project_dir\nhome = %(base)/myvenv\nchdir = %(base)/dir1/app_dir\nuwsgi-file = %(chdir)/app_dir/wsgi.py\nmodule = app_dir.wsgi:application\nenv = DJANGO_SETTINGS_MODULE=app_dir.settings\ncallable = application\nmaster = True\nprocesses = 5\nsocket = %(base)/dir2/uwsgi.sock\n;for UDS(Unix Domain Socket)\n;Default mode also can use UDS \nchmod-socket = 666\nvacuum = True\npidfile = /tmp/emperor.pid\ndeamonize = /home/%(uid)/main_dir/dir2/emperor.log\n```\n\nThis is Emperor mode\t\t\n\nIf you need to deploy a big number of apps on a single server, or a group of servers, the Emperor mode is just the ticket.\t \t\n\nStart command: `sudo uwsgi --emperor /etc/wusgi/vassals --uid user_name gid group_name`\t\t \n\nIf you have emperor_wusgi.ini file,\t\t \n\nStart command: `sudo nginx -s reload \u0026\u0026 sudo uwsgi --emperor /etc/uwsgi/vassals --uid user_name --gid group_name`\t\t \t\t\n  \nIf you feel like Start command's options are too many and command is too long, then you can make *.ini file about Emperor process\t\n\n```shell\n$ cd /etc/uwsgi\n$ vi uwsgi_emperor.ini\n[uwsgi]\nemperor = /etc/uwsgi/vassals\nuid = user_name\ngid = group_name\nmaster =True\npidfile = /tmp/emperor.pid\nvacuum = Ture\ndaemonize = /var/log/uwsgi/emperor.log\n```\nStart command: `sudo nginx -s reload \u0026\u0026 sudo uwsgi --ini /etc/uwsgi/uwsgi_emperor.ini`\t \t\n\nStop command: `sudo nginx -s stop \u0026\u0026 sudo uwsgi --stop /tmp/emperor.pid`\t\t \t\n\t\t\t\nGeneral(Default) mode\t\t\n---------------------\n\t\t\n```\n$ cd /home/user_name/main_project/dir2/\n$ vi uwsgi.ini\n[uwsgi]\nuid = user_name\nbase = /home/%(uid)/main_dir\nroot /home/user_name/main_dir/dir1/project_dir\nhome = %(base)/myvenv\nchdir = %(base)/dir1/proejct_dir\nuwsgi-file = %(chdir)/app_dir/wsgi.py\nmodule = app_dir.wsgi:application\nenv = DJANGO_SETTINGS_MODULE=app_dir.settings\ncallable = application\nmaster = true\nprocesses = 5\npidfile=/tmp/sample_master.pid\nsocket = %(base)/dir2/uwsgi.sock\nchmod-socket = 666\nvacuum = true\ndeamonize = /home/user_dir/main_dir/dir2/sample.log\n;This is uwsgi default mode not emperor\n;It is possible to create and run config files with general user accounts\n;Start or Stop commands are supposed to be executed in project directory\n;Start command: uwsgi --ini dir2/uwsgi.ini\n;Stop command: uwsgi --stop /tmp/sample_master.pid\n```\n\t\t\n## 13. sftp\t\t\n\t\n\t\t\n```shell\n$ vi /etc/ssh/sshd_config\n```\n\n```\n# Chagne or type\n\n#Subsystem sftp /usr/libexec/opnssh/sftp-server  \nSubsystem sftp internal -sftp\n\nMatch Group group_name\n    X11Forwarding no\n    AllowTcpForwarding no\n    ForceCommand internal-sftp\n    ChrootDirectory /home/user_dir\nMatch User user_name\n    PasswordAuthentication yes\n    ChrootDirectory /home/user_dir\n```\n\n```shell\n$ chown -R user_name.group_name /home/usr_name\n$ chown root.group_name /home/user_name\n$ chmod -R 755 /home/user_name\n$ service sshd start\n$ cd /home\n$ ls -al\ndrwxr-xr-x   3 root group 4096 Sep  4 14:45 user_name(directory)\n```\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgigibean%2Fdjango-nginx-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgigibean%2Fdjango-nginx-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgigibean%2Fdjango-nginx-server/lists"}