Django 的生产环境部署
web server 主流的两个web服务器。Nginx 和 apache
https://www.cnblogs.com/alex3714/p/6538374.html
https://www.cnblogs.com/qingspace/p/6838747.html
https://blog.csdn.net/Mandmg/article/details/60963721
监控使用如下 工具
sudo pip3 install uwsgitop
uwsgitop :9191
配置nginx
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
rico@rico-virtual-machine:~$ ls /etc/nginx/sites-enabaled/ ls: 无法访问'/etc/nginx/sites-enabaled/': 没有那个文件或目录 rico@rico-virtual-machine:~$ ls /etc/nginx/sites-enabled/ default rico@rico-virtual-machine:~$ dir pycharm-2018.2.1 snap 公共的 模板 视频 图片 文档 下载 音乐 桌面 rico@rico-virtual-machine:~$ cd 桌面 rico@rico-virtual-machine:~/桌面$ ls clearn python学习 uwsgi_test vmware-tools-distrib rico@rico-virtual-machine:~/桌面$ cd python学习/ rico@rico-virtual-machine:~/桌面/python学习$ ls 201811-day1 websites rico@rico-virtual-machine:~/桌面/python学习$ cd websites/ rico@rico-virtual-machine:~/桌面/python学习/websites$ ls mysites rico@rico-virtual-machine:~/桌面/python学习/websites$ cd mysites/ rico@rico-virtual-machine:~/桌面/python学习/websites/mysites$ ls blog manage.py mysites_nginx.conf templates uwsgi.ini.bak db.sqlite3 mysites statics uwsgi.ini uwsgi_params rico@rico-virtual-machine:~/桌面/python学习/websites/mysites$ dir blog manage.py mysites_nginx.conf templates uwsgi.ini.bak db.sqlite3 mysites statics uwsgi.ini uwsgi_params rico@rico-virtual-machine:~/桌面/python学习/websites/mysites$ sudo ln -s nginx.conf /etc/nginx/sites-enabled/ [sudo] rico 的密码: rico@rico-virtual-machine:~/桌面/python学习/websites/mysites$ ls /etc/nginx/sites-enabaled/ ls: 无法访问'/etc/nginx/sites-enabaled/': 没有那个文件或目录 rico@rico-virtual-machine:~/桌面/python学习/websites/mysites$ ls /etc/nginx/sites-enabled/ default nginx.conf rico@rico-virtual-machine:~/桌面/python学习/websites/mysites$ ls -l /etc/nginx/sites-enabled/ 总用量 0 lrwxrwxrwx 1 root root 34 12月 6 14:54 default -> /etc/nginx/sites-available/default lrwxrwxrwx 1 root root 10 12月 6 16:12 nginx.conf -> nginx.conf rico@rico-virtual-machine:~/桌面/python学习/websites/mysites$ /etc/init.d/nginx restart [....] Restarting nginx (via systemctl): nginx.serviceJob for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details. failed! rico@rico-virtual-machine:~/桌面/python学习/websites/mysites$ /etc/init.d/nginx restarty Usage: nginx {start|stop|restart|reload|force-reload|status|configtest|rotate|upgrade} rico@rico-virtual-machine:~/桌面/python学习/websites/mysites$ /etc/init.d/nginx restart [....] Restarting nginx (via systemctl): nginx.serviceJob for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details. failed! rico@rico-virtual-machine:~/桌面/python学习/websites/mysites$ sudo /etc/init.d/nginx restart [....] Restarting nginx (via systemctl): nginx.serviceJob for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details. failed! rico@rico-virtual-machine:~/桌面/python学习/websites/mysites$ sudo vim /var/www/rico@rico-virtual-machine:~/桌面/python学习/websites/mysites$ rico@rico-virtual-machine:~/桌面/python学习/websites/mysites$ rico@rico-virtual-machine:~/桌面/python学习/websites/mysites$ rico@rico-virtual-machine:~/桌面/python学习/websites/mysites$ sudo /etc/init.d/nginx restart [....] Restarting nginx (via systemctl): nginx.serviceJob for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details. failed! rico@rico-virtual-machine:~/桌面/python学习/websites/mysites$ sudo /etc/init.d/nginx stop [ ok ] Stopping nginx (via systemctl): nginx.service. rico@rico-virtual-machine:~/桌面/python学习/websites/mysites$ sudo /etc/init.d/nginx start [....] Starting nginx (via systemctl): nginx.serviceJob for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details. failed! rico@rico-virtual-machine:~/桌面/python学习/websites/mysites$ rico@rico-virtual-machine:~/桌面/python学习/websites/mysites$ systemctl status nginx.service ● nginx.service - A high performance web server and a reverse proxy server Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled) Active: failed (Result: exit-code) since Thu 2018-12-06 16:18:06 CST; 50s ago Docs: man:nginx(8) Process: 7581 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited, status=0/SUCCES Process: 7478 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS) Process: 7761 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=1/FAILURE) Main PID: 7479 (code=exited, status=0/SUCCESS) 12月 06 16:18:06 rico-virtual-machine systemd[1]: Starting A high performance web server and a reverse proxy server... 12月 06 16:18:06 rico-virtual-machine nginx[7761]: nginx: [emerg] open() "/etc/nginx/sites-enabled/nginx.conf" failed (40: Too many l 12月 06 16:18:06 rico-virtual-machine nginx[7761]: nginx: configuration file /etc/nginx/nginx.conf test failed 12月 06 16:18:06 rico-virtual-machine systemd[1]: nginx.service: Control process exited, code=exited status=1 12月 06 16:18:06 rico-virtual-machine systemd[1]: nginx.service: Failed with result 'exit-code'. 12月 06 16:18:06 rico-virtual-machine systemd[1]: Failed to start A high performance web server and a reverse proxy server. lines 1-15/15 (END) ● nginx.service - A high performance web server and a reverse proxy server Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: en Active: failed (Result: exit-code) since Thu 2018-12-06 16:18:06 CST; 50s ago Docs: man:nginx(8) Process: 7581 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 - Process: 7478 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code Process: 7761 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process Main PID: 7479 (code=exited, status=0/SUCCESS) 12月 06 16:18:06 rico-virtual-machine systemd[1]: Starting A high performance we 12月 06 16:18:06 rico-virtual-machine nginx[7761]: nginx: [emerg] open() "/etc/n 12月 06 16:18:06 rico-virtual-machine nginx[7761]: nginx: configuration file /et 12月 06 16:18:06 rico-virtual-machine systemd[1]: nginx.service: Control process 12月 06 16:18:06 rico-virtual-machine systemd[1]: nginx.service: Failed with res 12月 06 16:18:06 rico-virtual-machine systemd[1]: Failed to start A high perform ~ ~ ~ ~ ~ ~ ~ ~ rico@rico-virtual-machine:~/桌面/python学习/websites/mysites$ systemctl status nginx.service -l ● nginx.service - A high performance web server and a reverse proxy server Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: en Active: failed (Result: exit-code) since Thu 2018-12-06 16:18:06 CST; 2min 49 Docs: man:nginx(8) Process: 7581 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 - Process: 7478 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code Process: 7761 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process Main PID: 7479 (code=exited, status=0/SUCCESS) 12月 06 16:18:06 rico-virtual-machine systemd[1]: Starting A high performance we 12月 06 16:18:06 rico-virtual-machine nginx[7761]: nginx: [emerg] open() "/etc/n 12月 06 16:18:06 rico-virtual-machine nginx[7761]: nginx: configuration file /et 12月 06 16:18:06 rico-virtual-machine systemd[1]: nginx.service: Control process 12月 06 16:18:06 rico-virtual-machine systemd[1]: nginx.service: Failed with res 12月 06 16:18:06 rico-virtual-machine systemd[1]: Failed to start A high perform lines 1-15/15 (END)...skipping... ● nginx.service - A high performance web server and a reverse proxy server Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled) Active: failed (Result: exit-code) since Thu 2018-12-06 16:18:06 CST; 2min 49s ago Docs: man:nginx(8) Process: 7581 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited, status=0/SUCCES Process: 7478 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS) Process: 7761 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=1/FAILURE) Main PID: 7479 (code=exited, status=0/SUCCESS) 12月 06 16:18:06 rico-virtual-machine systemd[1]: Starting A high performance web server and a reverse proxy server... 12月 06 16:18:06 rico-virtual-machine nginx[7761]: nginx: [emerg] open() "/etc/nginx/sites-enabled/nginx.conf" failed (40: Too many l 12月 06 16:18:06 rico-virtual-machine nginx[7761]: nginx: configuration file /etc/nginx/nginx.conf test failed 12月 06 16:18:06 rico-virtual-machine systemd[1]: nginx.service: Control process exited, code=exited status=1 12月 06 16:18:06 rico-virtual-machine systemd[1]: nginx.service: Failed with result 'exit-code'. 12月 06 16:18:06 rico-virtual-machine systemd[1]: Failed to start A high performance web server and a reverse proxy server. ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ rico@rico-virtual-machine:~/桌面/python学习/websites/mysites$ netstat -ntlp | grep 80 (并非所有进程都能被检测到,所有非本用户的进程信息将不会显示,如果想看到所有信息,则必须切换到 root 用户) tcp 0 0 127.0.0.1:8001 0.0.0.0:* LISTEN 7516/uwsgi tcp 0 0 0.0.0.0:8000 0.0.0.0:* LISTEN 7516/uwsgi rico@rico-virtual-machine:~/桌面/python学习/websites/mysites$ ps -ef | grep 80 root 80 2 0 12:52 ? 00:00:00 [scsi_tmf_0] root 180 2 0 12:52 ? 00:00:00 [scsi_tmf_2] whoopsie 1803 1 0 12:52 ? 00:00:00 /usr/bin/whoopsie -f kernoops 1806 1 0 12:52 ? 00:00:00 /usr/sbin/kerneloops --test kernoops 1808 1 0 12:52 ? 00:00:00 /usr/sbin/kerneloops rico 7800 7531 0 16:23 pts/0 00:00:00 grep --color=auto 80 rico@rico-virtual-machine:~/桌面/python学习/websites/mysites$ top top - 16:26:10 up 3:34, 1 user, load average: 0.32, 0.18, 0.11 任务: 277 total, 1 running, 214 sleeping, 0 stopped, 0 zombie %Cpu(s): 2.1 us, 2.5 sy, 0.0 ni, 95.4 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st KiB Mem : 2993772 total, 1127244 free, 1435156 used, 431372 buff/cache KiB Swap: 969960 total, 965864 free, 4096 used. 1309624 avail Mem 进程 USER PR NI VIRT RES SHR � %CPU %MEM TIME+ COMMAND 2154 rico 20 0 521052 75876 31072 S 3.9 2.5 1:24.42 Xorg 2707 rico 20 0 913976 35700 19036 S 3.0 1.2 0:43.32 gnome-term+ 2341 rico 20 0 3059032 161676 32192 S 1.0 5.4 2:53.40 gnome-shell 1 root 20 0 160200 6592 4196 S 0.7 0.2 0:06.95 systemd 7801 rico 20 0 51352 3896 3204 R 0.7 0.1 0:00.23 top 2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd 4 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 kworker/0:+ 6 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 mm_percpu_+ 7 root 20 0 0 0 0 S 0.0 0.0 0:02.42 ksoftirqd/0 8 root 20 0 0 0 0 I 0.0 0.0 0:04.00 rcu_sched 9 root 20 0 0 0 0 I 0.0 0.0 0:00.00 rcu_bh 10 root rt 0 0 0 0 S 0.0 0.0 0:00.00 migration/0 11 root rt 0 0 0 0 S 0.0 0.0 0:00.07 watchdog/0 12 root 20 0 0 0 0 S 0.0 0.0 0:00.00 cpuhp/0 13 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kdevtmpfs 14 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 netns 15 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_tasks_+ rico@rico-virtual-machine:~/桌面/python学习/websites/mysites$ netstat -ntlp | grep 80 (并非所有进程都能被检测到,所有非本用户的进程信息将不会显示,如果想看到所有信息,则必须切换到 root 用户) rico@rico-virtual-machine:~/桌面/python学习/websites/mysites$ sudo netstat -ntlp | grep 80 rico@rico-virtual-machine:~/桌面/python学习/websites/mysites$ ps -ef | grep 80 root 80 2 0 12:52 ? 00:00:00 [scsi_tmf_0] root 180 2 0 12:52 ? 00:00:00 [scsi_tmf_2] whoopsie 1803 1 0 12:52 ? 00:00:00 /usr/bin/whoopsie -f kernoops 1806 1 0 12:52 ? 00:00:00 /usr/sbin/kerneloops --test kernoops 1808 1 0 12:52 ? 00:00:00 /usr/sbin/kerneloops rico 7807 7531 0 16:26 pts/0 00:00:00 ps -ef rico 7808 7531 0 16:26 pts/0 00:00:00 grep --color=auto 80 rico@rico-virtual-machine:~/桌面/python学习/websites/mysites$ sudo /etc/init.d/nginx restart [....] Restarting nginx (via systemctl): nginx.serviceJob for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details. failed! rico@rico-virtual-machine:~/桌面/python学习/websites/mysites$ ls blog db.sqlite3 manage.py mysites mysites_nginx.conf statics templates uwsgi.ini uwsgi.ini.bak uwsgi_params rico@rico-virtual-machine:~/桌面/python学习/websites/mysites$ sudo mv mysites_nginx.conf /etc/nginx/sites-enabled/ rico@rico-virtual-machine:~/桌面/python学习/websites/mysites$ ls /etc/nginx/s scgi_params sites-available/ sites-enabled/ snippets/ rico@rico-virtual-machine:~/桌面/python学习/websites/mysites$ ls /etc/nginx/sites-enabled/ default mysites_nginx.conf nginx.conf rico@rico-virtual-machine:~/桌面/python学习/websites/mysites$ ls -l /etc/nginx/sites-enabled/ 总用量 4 lrwxrwxrwx 1 root root 34 12月 6 14:54 default -> /etc/nginx/sites-available/default -rw-r--r-- 1 rico rico 1116 12月 6 15:54 mysites_nginx.conf lrwxrwxrwx 1 root root 10 12月 6 16:12 nginx.conf -> nginx.conf rico@rico-virtual-machine:~/桌面/python学习/websites/mysites$ rm -rf /etc/nginx/sites-enabled/nginx.conf rm: 无法删除'/etc/nginx/sites-enabled/nginx.conf': 权限不够 rico@rico-virtual-machine:~/桌面/python学习/websites/mysites$ sudo rm -rf /etc/nginx/sites-enabled/nginx.conf rico@rico-virtual-machine:~/桌面/python学习/websites/mysites$ ls -l /etc/nginx/sites-enabled/ 总用量 4 lrwxrwxrwx 1 root root 34 12月 6 14:54 default -> /etc/nginx/sites-available/default -rw-r--r-- 1 rico rico 1116 12月 6 15:54 mysites_nginx.conf rico@rico-virtual-machine:~/桌面/python学习/websites/mysites$ ls -l /etc/nginx/sites-enabled/ 总用量 4 lrwxrwxrwx 1 root root 34 12月 6 14:54 default -> /etc/nginx/sites-available/default -rw-r--r-- 1 rico rico 1116 12月 6 15:54 mysites_nginx.conf rico@rico-virtual-machine:~/桌面/python学习/websites/mysites$ /etc/init.d/nginx start [ ok ] Starting nginx (via systemctl): nginx.service. rico@rico-virtual-machine:~/桌面/python学习/websites/mysites$ /etc/init.d/nginx stop [ ok ] Stopping nginx (via systemctl): nginx.service. rico@rico-virtual-machine:~/桌面/python学习/websites/mysites$ /etc/init.d/nginx start [....] Starting nginx (via systemctl): nginx.serviceJob for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details. failed! rico@rico-virtual-machine:~/桌面/python学习/websites/mysites$ /etc/init.d/nginx start [ ok ] Starting nginx (via systemctl): nginx.service. rico@rico-virtual-machine:~/桌面/python学习/websites/mysites$
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
rico@rico-virtual-machine:~$ ls pycharm-2018.2.1 snap 公共的 模板 视频 图片 文档 下载 音乐 桌面 rico@rico-virtual-machine:~$ cd 桌面 rico@rico-virtual-machine:~/桌面$ ls clearn python学习 uwsgi_test vmware-tools-distrib rico@rico-virtual-machine:~/桌面$ cd python学习/ rico@rico-virtual-machine:~/桌面/python学习$ ls 201811-day1 websites rico@rico-virtual-machine:~/桌面/python学习$ cd websites/ rico@rico-virtual-machine:~/桌面/python学习/websites$ ls mysites rico@rico-virtual-machine:~/桌面/python学习/websites$ cd mysites/ rico@rico-virtual-machine:~/桌面/python学习/websites/mysites$ ls blog manage.py statics uwsgi.ini uwsgi_params db.sqlite3 mysites templates uwsgi.ini.bak rico@rico-virtual-machine:~/桌面/python学习/websites/mysites$ /etc/init.d/nginx start[ ok ] Starting nginx (via systemctl): nginx.service. rico@rico-virtual-machine:~/桌面/python学习/websites/mysites$ uwsgi uwsgi.ini
网站部署上线admin静态文件无法正常显示 | Django
# 在部署上下之后无法正常显示后台admin的静态文件 # 因为文件都在django内部,而在nginx中将配置都设置到一个位置; # 措施: 1.在settings.py文件中添加配置; STATIC_ROOT = "all_static_files" 2.执行命令,读取所有static文件到项目目录中; python3 manage.py collectstatic 3.修改nginx配置; location /static{ alias/home/alex/CreazyEye/all_static_files; }
https://www.cnblogs.com/jiangwangxiang/p/8481661.html
https://www.django.cn/article/show-21.html
https://blog.csdn.net/u011450033/article/details/79702658
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
Microsoft Windows [版本 6.1.7601] 版权所有 (c) 2009 Microsoft Corporation。保留所有权利。 D:\Program Files (x86)\python36\Lib\site-packages>wfastcgi-enable ERROR ( message:新 application 对象缺少必需的属性。在组合的密钥属性“fullPath, arguments”分别设置为“"d:\program files (x86)\python36\python.exe", "d:\program files (x86)\python36\lib\site-packages\wfastcgi.py"”时,无法添加类型为“application”的重复集合项 。 ) An error occurred running the command: ['C:\\Windows\\system32\\inetsrv\\appcmd.exe', 'set', 'config', '/section:system.webServer/fastCGI', '/+[fullPath=\'"d:\\program files (x86)\\python36\\python.e xe"\', arguments=\'"d:\\program files (x86)\\python36\\lib\\site-packages\\wfastcgi.py"\', signalBeforeTerminateSeconds=\'30\']'] Ensure your user has sufficient privileges and try again. D:\Program Files (x86)\python36\Lib\site-packages>wfastcgi-disable 已经在配置提交路径“MACHINE/WEBROOT/APPHOST”向“MACHINE/WEBROOT/APPHOST”的“system.webServer/fastCgi”节应用了配置更改 ""d:\program files (x86)\python36\python.exe"|"d:\program files (x86)\python36\lib\site-packages\wfastcgi.py"" is no longer registered for use with FastCGI D:\Program Files (x86)\python36\Lib\site-packages>%windir%\system32\inetsrv\appcmd unlock config -section:system.webServer/handlers 在配置路径“MACHINE/WEBROOT/APPHOST”解除了“system.webServer/handlers”节的锁定。 D:\Program Files (x86)\python36\Lib\site-packages>%windir%\system32\inetsrv\appcmd unlock config -section:system.webServer/modules 在配置路径“MACHINE/WEBROOT/APPHOST”解除了“system.webServer/modules”节的锁定。 D:\Program Files (x86)\python36\Lib\site-packages>
搭建Git仓库 在服务器 上 Windows
https://blog.csdn.net/u011781521/article/details/78337632
https://www.cnblogs.com/yejq/p/4455430.html
https://www.cnblogs.com/senyier/p/7272515.html