web网站架构和Nginx

web网站架构和Nginx

1.LNMP(基于python的web架构)
Linux+nginx+mysql+python
2.静态资源:客户端从服务器获得的资源表现形式与原文件相同
动态资源:通常是程序文件,需要服务器执行后,将执行结果返回给客户端。
3.主流httpd服务器:Apache Nginx
4.WSGI:Web服务器网关接口(Python Web Server Gateway Interface)
Python语言定义的Web服务器和Web应用程序或框架之间的一种简单而通用的接口。
自从WSGI被开发出来以后,许多其它语言中也出现了类似接口。
5.nginx:基于异步非阻塞I/O模型
安装方法
源码:编译安装
官方的deb包
sudo apt-get -y install nginx
配置文件目录:/etc/nginx
主配置文件: /etc/nginx/nginx.conf
uwsgi参数配置文件:/etc/nginx/uwsgi_params
被主配置文件包含的配置文件:/etc/nginx/sites-available/default
网页根路径:/var/www/html
wsgi的web实现

sudo apt-get -y install build-essential python3-dev python3-pip python-pip curl#安装
cd /tmp
sudo pip3 install uwsgi
sudo curl http://uwsgi.it/install | bash -s default /tmp/uwsgi
sudo mkdir /myweb
cd /myweb
sudo vim test.py
////////////
在新建的test.py里面写上下面代码
def application(env,start_response):
body = ‘hello ujiuye.’
status = ‘200 OK’
headers = [(‘content-type’, ‘text/html’), (‘content-length’,str(len(body))) ]
start_response(status,headers)
return [body.encode()]
/////////
在浏览器里面输入ip地址加端口号和html文件位置
建立通信
sudo uwsgi --http :9090 --wsgi-file /myweb/test.py --master --processes 4 --threads 2

Nginx反向代理uwsgi,实现静态页面和动态页面的分离
Nginx实现反向代理,需要基于proxy模块,

在/etc/nginx/sites-available/default文件里面的server中的location 下新增
在这里插入图片描述
sudo nginx -t (检查语法)
sudo service nginx restart (重启服务)
在浏览器里面输入IP地址+/test.py

猜你喜欢

转载自blog.csdn.net/qq_34681895/article/details/85332016