-------------------linux环境设置------------------
#防火墙开放端口
firewall-cmd --list-all
firewall-cmd --zone=public --add-port=9621/tcp --permanent
firewall-cmd --reload
#防火墙删除端口
firewall-cmd --zone=public --remove-port=8888/tcp --permanent
firewall-cmd --reload
#开放http端口
semanage port -a -t http_port_t -p tcp 9621
#关闭http端口
semanage port -d -t http_port_t -p tcp 9621
#查看http端口状态
semanage port -l | grep http
#selinux允许http连接
setsebool -P httpd_can_network_connect 1
#暂时关闭selinux
setenforce 0
#开启selinux
setenforce 1
#按端口查询进程
lsof -i :9621
-------------------Django项目------------------
#新建Django项目
django-admin startproject myweb
#selinux允许访问项目路径
chcon -R -t httpd_sys_content_t '/root/myweb'
#重建表结构
cd /root/myweb
python3 manage.py migrate
#修改settings.py
vim /root/myweb/myweb/settings.py
ALLOWED_HOSTS = ['*']
STATIC_ROOT = '/root/myweb/static'
#测试项目是否正常运行
python3 /root/myweb/manage.py runserver 0.0.0.0:9621
#新建样式目录static
cd /root/myweb
mkdir static
python3 manage.py collectstatic
#若使用mysql,在项目的__init__.py文件添加如下内容
import pymysql
pymysql.install_as_MySQLdb()
#settings文件中修改
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # 数据库引擎
'NAME': 'djangodb', # 数据库名
'USER': 'root', # 账号
'PASSWORD': 'root', # 密码
'HOST': '127.0.0.1', # HOST
'POST': 3306, # 端口
}
}
#创建管理员
python3 /root/myweb/manage.py createsuperuser
-------------------uwsgi项目------------------
#安装uwsgi
#apt install gcc
yum install gcc
pip3 install uwsgi --upgrade
#启动wsgi
uwsgi --http :9621 --chdir /root/myweb --static-map /static=/root/myweb/static --module myweb.wsgi
#使用uwsgi.ini启动
#uwsgi --ini /root/myweb/uwsgi.ini
#项目目录下新建uwsgi.ini,后续使用WinSCP配置文件
vim /root/myweb/uwsgi.ini
#添加并保存
[uwsgi]
socket = :8888
chdir = /root/myweb
module = myweb.wsgi
master = true
processes = 4
vacuum = true
pidfile = %(chdir)/uwsgi.pid
static-map = /static=/root/myweb/static
#http = :9622
#uwsgi任务开机自启
vim /lib/systemd/system/uwsgi.service
#添加并保存
[Unit]
Description=uwsgi
After=network.target
[Service]
User=root
ExecStart=uwsgi --ini /root/myweb/uwsgi.ini
ExecStop=uwsgi --stop /root/myweb/uwsgi.pid
ExecReload=uwsgi --reload /root/myweb/uwsgi.pid
[Install]
WantedBy=multi-user.target
#启动、停止、重启、自启动、不自启、状态 uwsgi1
systemctl start uwsgi.service
systemctl stop uwsgi.service
systemctl restart uwsgi.service
systemctl enable uwsgi.service
systemctl disable uwsgi.service
systemctl status uwsgi.service
-------------------Nginx项目------------------
#安装 Nginx 等软件
#sudo yum install epel-release
#apt install nginx
sudo yum install nginx
#配置 Nginx,首次用WinSCP配置文件
vim /etc/nginx/nginx.conf
#修改并保存
user root;
events {
worker_connections 1024;
}
http {
server {
listen 9621;
server_name myweb;
charset UTF-8;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/myweb_access.log;
error_log /var/log/nginx/myweb_error.log;
client_max_body_size 75M;
location / {
include /etc/nginx/uwsgi_params;
uwsgi_pass 127.0.0.1:8888;
uwsgi_read_timeout 2;
}
location /static {
expires 30d;
autoindex on;
add_header Cache-Control private;
alias /root/myweb/stock/static/;
}
}
}
#启动、停止、重载、自启动、不自启、状态 Nginx
systemctl start nginx.service
systemctl stop nginx.service
systemctl restart nginx.service
systemctl enable nginx.service
systemctl disable nginx.service
systemctl status nginx.service
#重载系统服务
systemctl daemon-reload
centos8部署Django
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。