Try to build an environment like Python + uWSGI + Django + Nginx. I'm feeling better now, and I'm working with reference to other Qiita articles in the first place, so do I need to bother to write an article? There is a question, but well, I will leave it as a memorandum.
environment | URL |
---|---|
AWS | https://〜/hello/ |
If you want to increase the number of sites (apps), perform the following work.
--Create projects and apps in Django --Create nginx.conf, ini and service files for your growing site --Start the service
mkdir -p /WORK/etc;
mkdir -p /WORK/var/www;
mkdir -p /WORK/var/log;
mkdir -p /WORK/var/tmp;
mkdir /etc/nginx/sites-available;
mkdir /etc/nginx/sites-enabled;
/etc/nginx/nginx.conf
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
#-- WORK
include /etc/nginx/sites-enabled/*.conf;
}
/WORK/etc/nginx_myweb.conf
upstream django {
server 127.0.0.1:8001;
}
server {
#-- SSL
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
server_name WORK.work;
ssl_certificate "/etc/letsencrypt/live/WORK.work/fullchain.pem";
ssl_certificate_key "/etc/letsencrypt/live/WORK.work/privkey.pem";
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 10m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
charset utf-8;
client_max_body_size 75M;
#-- myweb
location /static {
alias /WORK/var/www/myweb/static;
}
location / {
uwsgi_pass django;
include /WORK/var/www/myweb/uwsgi_params;
}
}
/WORK/etc/myweb.ini
[uwsgi]
master = true
socket = :8001
module = myweb.wsgi
pythonpath = /WORK/var/www/myweb
logto = /WORK/var/log/uwsgi.log
pidfile = /WORK/var/tmp/uwsgi.pid
/WORK/etc/myweb.service
[Unit]
Description = myweb
After = syslog.target
[Service]
ExecStart = /usr/bin/uwsgi --ini /WORK/etc/myweb.ini
Restart=always
KillSignal=SIGQUIT
Type=notify
StandardError=syslog
NotifyAccess=all
[Install]
WantedBy=multi-user.target
Generate projects and apps in Django
Project generation
cd /WORK/var/www;
django-admin startproject myweb;
App generation
cd /WORK/var/www/myweb;
python manage.py startapp hello;
/WORK/var/www/myweb/myweb/settings.py
INSTALLED_APPS = [
<Omitted>
'hello',← Add
]
<End of sentence>
STATIC_ROOT = os.path.join(BASE_DIR, "static/")← Add
/WORK/var/www/myweb/hello/views.py
# Create your views here.
↑ Add below from here ↓ ↓ ↓
from django.http import HttpResponse
<Blank line>
def main(request):
return HttpResponse("Hello!")
/WORK/var/www/myweb/myweb/urls.py
import hello.views ← Add
from hello import views ← Add
<Blank line>
urlpatterns = [
<Omitted>
url(r'^hello/', hello.views.main),← Add
]
python manage.py migrate;
python manage.py collectstatic;
Nginx
ln -s /WORK/etc/nginx_myweb.conf /etc/nginx/sites-enabled/.;
systemctl status nginx;
systemctl start nginx;
systemctl stop nginx;
systemctl start nginx;
systemctl status nginx;
uWSGI
ln -s /WORK/etc/myweb.service /etc/systemd/system/myweb.service;
systemctl status myweb;
systemctl start myweb;
systemctl stop myweb;
systemctl start myweb;
systemctl status myweb;
--Implement 5 migrations (python manage.py migrate;
)
――Implement 6 uWSGI glue start (systemctl restart myweb;
)
Recommended Posts