Créez un environnement comme Python + uWSGI + Django + Nginx. Je me sens mieux maintenant, et je travaille avec des références à d'autres articles Qiita en premier lieu, alors dois-je prendre la peine d'écrire un article? Il y a une question, mais bon, je vais la laisser sous forme de mémoire.
environnement | URL |
---|---|
AWS | https://〜/hello/ |
Si vous souhaitez augmenter le nombre de sites (applications), effectuez le travail suivant.
--Créer des projets et des applications dans Django --Créer des fichiers nginx.conf, ini et de service pour les sites en croissance --Démarrez le 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
Générer des projets et des applications avec Django
Génération de projet
cd /WORK/var/www;
django-admin startproject myweb;
Génération d'applications
cd /WORK/var/www/myweb;
python manage.py startapp hello;
/WORK/var/www/myweb/myweb/settings.py
INSTALLED_APPS = [
<Omis>
'hello',← Ajouter
]
<Fin de phrase>
STATIC_ROOT = os.path.join(BASE_DIR, "static/")← Ajouter
/WORK/var/www/myweb/hello/views.py
# Create your views here.
↑ Ajouter ci-dessous à partir d'ici ↓ ↓ ↓
from django.http import HttpResponse
<Ligne vide>
def main(request):
return HttpResponse("Hello!")
/WORK/var/www/myweb/myweb/urls.py
import hello.vues ← Ajouter
depuis bonjour les vues d'importation ← Ajouter
<Ligne vide>
urlpatterns = [
<Omis>
url(r'^hello/', hello.views.main),← Ajouter
]
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;
--Implémenter 5 migrations (python manage.py migrate;
)
――Implément 6 uWSGI glue start (systemctl restart myweb;
)
Recommended Posts