Django个人博客搭建教程---Ubuntu+uwsgi+Nginx腾讯云部署

1、安装uswgi

pip3 install uwsgi

2、安装Nginx

sudo apt-get install nginx

3、在项目根目录下创建一个uwsgi.ini文件

[uwsgi] 
chdir = /home/mysite
module = mysite.wsgi:application
socket          = 127.0.0.1:8001
master = true 
processes = 1
threads = 2
max-requests = 6000
chmod-socket    = 666
buffer-size    = 65535
logto = /var/log/mysite.log
async
ugreen =''
http-timeout = 300
#plugins=python

4、修改/etc/nginx/nginx.conf文件

在http{}里加入这一段即可

这里我们Nginx会监听80端口,转发给8000端口,uswgi监听8000端口然后给Django去处理

server {   		# 这个server标识我要配置了
		listen 80;  # 我要监听那个端口
		server_name 118.25.79.249 ;  # 你访问的路径前面的url名称
		charset  utf-8; # Nginx编码
		gzip on;  # 启用压缩,这个的作用就是给用户一个网页,比如3M压缩后1M这样传输速度就会提高很多
		gzip_types text/plain application/x-javascript text/css text/javascript application/x-httpd-php application/json text/json image/jpeg image/gif image/png application/octet-stream;  # 支持压缩的类型

		error_page  404           		/404.html;  # 错误页面
		error_page   500 502 503 504  /50x.html;  # 错误页面

		# 指定项目路径uwsgi
		location / {        # 这个location就和咱们Django的url(r'^admin/', admin.site.urls),
			include uwsgi_params;  # 导入一个Nginx模块他是用来和uWSGI进行通讯的
			uwsgi_connect_timeout 30;  # 设置连接uWSGI超时时间
			uwsgi_pass  127.0.0.1:8000;
		}

		# 指定静态文件路径
		location /static/ {
			alias  /home/mysite/static/;
		}
	}

5、访问你的ip即可

http://118.25.79.249/

发布了214 篇原创文章 · 获赞 72 · 访问量 152万+

猜你喜欢

转载自blog.csdn.net/ssjdoudou/article/details/104018230