CENTOS8+PYTHON3.6+DJANGO3+UWSGI+NGINX配置说明(亲自实践经验)
本人买的阿里云服务器,选择的是CENTOS8,里面自带了PYTHON3.6,
安装uwsgi
pip3 install uwsgi 也可能是pip install uwsgi
安装DJANGO
pip3 install django 也可能是pip install django
安装NGINX
yum -y install nginx
用DJANGO建个简单的项目测试,我建的目录是/data/wwwroot/mysite,我的项目mysite目录下是如下文件
项目中建个APP为blog,
/data/wwwroot/mysite/mysite/urls.py内容如下
from django.contrib import admin
from django.urls import path
from blog import views
urlpatterns = [
path('admin/', admin.site.urls),
path('',views.index,name='index'),
]
/data/wwwroot/mysite/mysite/settings.py内容如下
DEBUG = False
ALLOWED_HOSTS = ['www.gzqq.top','gzqq.top']
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'blog',
]
这里只列出了部分内容,其它内容自动的,不用修改
/data/wwwroot/mysite/blog/views.py内容如下
from django.shortcuts import render
# Create your views here.
from django.http import HttpResponse
def index(request):
return HttpResponse('HELLO.欢迎来到股指期权网:网址www.gzqq.top,如果有问题请联系QQ30237333')
uwsgi.ini内容如下,文件地址/data/wwwroot/mysite/uwsgi.ini
[uwsgi]
# Django-related settings
socket = :8088
# the base directory (full path)
chdir = /data/wwwroot/mysite
# Django s wsgi file
module = mysite.wsgi
# process-related settings
# master
master = true
# maximum number of worker processes
processes = 4
# ... with appropriate permissions - may be needed
# chmod-socket = 664
# clear environment on exit
vacuum = true
pidfile=uwsgi/uwsgi.pid
# 在后台运行, 信息保存的日志文件
daemonize=uwsgi/uwsgi.log
nginx.conf文件内容如下,这个文件就是修改了/etc/nginx/nginx.conf这个文件,修改前记的要备份一份
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
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;
server {
listen 80;
#listen [::]:80 default_server;
server_name www.gzqq.top;
#root /usr/share/nginx/html;
# Load configuration files for the default server block.
#include /etc/nginx/default.d/*.conf;
charset utf-8;
access_log /data/wwwroot/mysite/access.log;
error_log /data/wwwroot/mysite/error.log;
client_max_body_size 75M;
location /static {
alias /data/wwwroot/mysite/static/;
}
location / {
include /etc/nginx/uwsgi_params;
uwsgi_pass 127.0.0.1:8088;
}
}
}
现在uwsgi.ini和nginx.conf都配置好了,下面就要运行,运行的时候记的要按以下步骤来
killall -9 uwsgi
killall -9 nginx
以上两条是要杀掉原来的配置进程,以免启动之后还是老的配置在起作用
下面继续
cd /data/wwwroot/mysite
在此目录下运行
uwsgi --ini uwsgi.ini
nginx -s reload
如果是第一次运行nginx的话就运行下面的命令
/usr/sbin/nginx
下面到浏览器运行www.gzqq.top
会显示 HELLO.欢迎来到股指期权网:网址www.gzqq.top,如果有问题请联系QQ30237333'
好了,有问题请联系我的QQ