当前位置: 首页 > news >正文

萧山网站制作公司北京网站优化经理

萧山网站制作公司,北京网站优化经理,网页设计就业,突唯阿 领先的响应式网站建设平台1.1 问题 配置Nginx使其可以将动态访问转交给uWSGI: 1.2 方案 安装Python工具及依赖 安装uWSGI并编写配置文件 1.3 步骤 实现此案例需要按照如下步骤进行。 步骤一: 1)安装python依赖软件[rootproxy python]# yum -y install gcc make pytho…

1.1 问题

配置Nginx使其可以将动态访问转交给uWSGI:

1.2 方案

安装Python工具及依赖

安装uWSGI并编写配置文件

1.3 步骤

实现此案例需要按照如下步骤进行。

步骤一:

1)安装python依赖软件[root@proxy python]# yum  -y install  gcc  make  python3  python3-devel
2)安装项目依赖[root@proxy python]# pip3 install  pytz-2022.6-py2.py3-none-any.whl
[root@proxy python]# pip3 install  Django-1.11.8-py2.py3-none-any.whl
[root@proxy python]# pip3 install  django-bootstrap3-11.0.0.tar.gz
3)测试项目[root@proxy python]# tar -xf python-project-demo.tar.gz
[root@proxy python]# cd python-project-demo/
[root@proxy python-project-demo]# python3 manage.py runserver 0.0.0.0:8000

之后可在浏览器访问192.168.99.5:8000,测试完毕后按ctrl + c

注意:

测试时如果无法连接外网,可能需要将python-project-demo/learning_logs/templates/base.html文件中的特效注释<!--    {% bootstrap_css %}{% bootstrap_javascript %}
-->

步骤二:

1)安装uWSGI[root@proxy python-project-demo]# cd ..
[root@proxy python]# pip3 install uWSGI-2.0.21.tar.gz
[root@proxy python]# vim   myproject.ini
[uwsgi]
socket=127.0.0.1:8000                  #与web服务(nginx)通信的接口
chdir=/root/python/python-project-demo          #项目的工作目录
wsgi-file=learning_log/wsgi.py            #指定项目中的wsgi.py配置文件
daemonize=/var/log/uwsgi.log            #指定日志文件位置
#processes=4    #指定启动进程的数目
#master=true     #开启主进程管理模式
2)运行uWSGI[root@proxy python]# uwsgi --ini myproject.ini    #读取myproject.ini运行uWSGI
3)修改nginx配置文件,添加uWSGI转发[root@proxy python]# vim /usr/local/nginx/conf/nginx.conf
...location / {uwsgi_pass 127.0.0.1:8000;        #动态页面交给uWSGIinclude uwsgi_params;            #调用uWSGI配置文件root   html;index  index.html index.htm;}
...
[root@proxy python]# /usr/local/nginx/sbin/nginx

测试

使用浏览器访问192.168.99.5

2 案例2:配置Nginx实现用IP测试灰度发布

2.1 问题

本案例要求不同IP的客户访问相同代理时,可以看到不同集群主机的内容

2.2 方案

创建不同集群,准备多台集群主机,通过$remote_addr变量识别不同客户机

2.3 步骤

实现此案例需要按照如下步骤进行。

步骤一:

1)使用proxy主机在nginx配置中创建集群[root@proxy nginx]# vim /usr/local/nginx/conf/nginx.conf
http {    
...upstream s8001 {                    #测试集群1server 192.168.99.100:8001;}upstream s8002 {                    #测试集群2server 192.168.99.200:8002;}upstream default {                    #正常业务集群server 192.168.99.100:80;server 192.168.99.200:80;}server {listen       80;server_name  localhost;
...set $group "default";                    #定义变量$group,默认值defaultif ($remote_addr ~ "192.168.99.1"){        #如果客户机ip是99.1就访问集群1set $group s8001;}if ($remote_addr ~ "192.168.99.2"){        #如果客户机ip是99.2就访问集群1set $group s8002;}location / {proxy_pass http://$group;        #调用集群root   html;index  index.html index.htm;}
...
}

步骤二  为web1新建nginx虚拟主机

[root@web1 nginx]# vim /usr/local/nginx/conf/nginx.conf
http {    
...
server {listen 8001;server_name localhost;root html8001;index index.html;
}
...
}
[root@web1 nginx]# mkdir html8001
[root@web1 nginx]# echo web1-8001 > html8001/index.html

步骤三  为web2新建nginx虚拟主机

[root@web2 nginx]# vim /usr/local/nginx/conf/nginx.conf
http {
...
server {listen 8002;server_name localhost;root html8002;index index.html;
}
...
}
[root@web2 nginx]# mkdir html8002
[root@web2 nginx]# echo web1-8002 > html8002/index.html

步骤三 测试

192.168.99.1访问192.168.99.5192.168.99.2访问192.168.99.5其他ip访问192.168.99.5

3 案例3:通过不同用户ID测试灰度发布

3.1 问题

不同ID的客户访问相同代理时,可以看到不同集群主机的内容

3.2 方案

使用php页面,定义不同匹配语句

3.3 步骤

实现此案例需要按照如下步骤进行。

步骤一:

1)使用proxy主机,要先还原nginx,并配置可以解析动态网页

[root@web2 nginx]# vim html/home.php        #修改php页面,将原有Welcome那行修改成以下状态
Welcome :  <?php
if(preg_match("/^abc/",$_SESSION['login_user'])) {        #preg_match匹配正则,如果登录账号是以abc开头,就连接99.100,否则连接99.200
echo "<a href='http://192.168.99.100'>开始</a>";
}
else
{
echo "<a href='http://192.168.99.200'>开始</a>";
}
?>

2)测试

浏览器访问192.168.99.5/index.php分别输入不同名称的账户,可以看到"开始"连接的是不同的地址,效果如图-1所示。

图-1

4 案例4:配置网站限流限速

4.1 问题

本案例要求配置nginx限流限速,效果如下:

  • 使用Nginx配置全局限速100k
  • 配置虚拟主机www.b.com限速200k,该网站根目录下的file_a目录中的所有数据限速300k,file_b目录中的所有数据不限速

4.2 方案

使用limit_rate指令限制速度

4.3 步骤

实现此案例需要按照如下步骤进行。

步骤一:

1)定义limit_rate限制[root@web1 nginx]# vim /usr/local/nginx/conf/nginx.conf
http {
...    limit_rate 100k;        #全局限速server {limit_rate 200k;            #虚拟主机限速listen 80;server_name www.b.com;root html;index index.html;location /file_a {limit_rate 300k;        #file_a目录限速300k}location /file_b {limit_rate 0k;            #file_b目录不限速}}
2)创建测试目录[root@web1 nginx]# mkdir html/file_a
[root@web1 nginx]# mkdir html/file_b
3)创建测试文件[root@web1 nginx]# dd if=/dev/zero of=html/test.img  bs=100M count=1
[root@web1 nginx]# dd if=/dev/zero of=html/file_a/test.img  bs=100M count=1
[root@web1 nginx]# dd if=/dev/zero of=html/file_b/test.img  bs=100M count=1
下载测试wget www.a.com/test.imgwget www.b.com/test.imgwget www.b.com/file_a/test.imgwget www.b.com/file_b/test.img
连接限制(非必须配置)修改用户访问连接限制,使一个客户同时打开多个连接也无法突破限制首先安装ngx_http_limit_conn_module模块http {limit_conn_zone $binary_remote_addr zone=addr:10m;        server {
location /app {
limit_rate 30k;     
limit_conn addr 1 ;    
}

5 防盗链

valid_referers指令可以检测被访问资源从哪个地址来

1)修改配置,添加防盗链测试语句[root@web1 nginx]# vim /usr/local/nginx/conf/nginx.conf
server {
...    valid_referers  none 192.168.99.100;    #如果请求中的referer 头字段包含者地址是99.100或者没有referer 头字段则有效,if ($invalid_referer){                    #如果上述测试无效则条件成立return 403;                        #返回错误提示}
...
}
2)web1编写测试页面[root@web1 nginx]# cat html/index.html
web1
测试页面  --
<a href="http://192.168.99.100/nr.html">内容</a>
[root@web1 nginx]# cat html/nr.html
web1内容页面
3)web2编写测试页面[root@web2 nginx]# cat html/index.html
web2
测试页面  --
<a href="http://192.168.99.100/nr.html">内容</a>
4)测试,从192.168.99.100主页点内容可以访问,但从99.200点不可以

http://www.dt0577.cn/news/20586.html

相关文章:

  • 广州广告网站建设seo范畴
  • 网站怎么做安全可靠免费发广告网站
  • 乌鲁木齐做网站深圳全网推广公司
  • 贵阳网站建设优化最新国际新闻热点事件
  • 重庆网站建设培训班网站统计代码
  • 长宁武汉阳网站建设semester什么意思
  • dw网站结构图怎么做成都网站快速优化排名
  • asp企业网站自助建站系统免费版超漂亮版绍兴百度推广优化排名
  • 网站的功能测试怎么做的水果网络营销策划书
  • 淄博网站建设优化在线bt磁力搜索
  • 网站建设那个网站好百度指数是什么意思
  • 湖北住房城乡建设厅网站站长工具推荐网站
  • 湘潭市政府采购网seo百度首页排名业务
  • 网站设计 原型图百度一下你就知道了百度一下
  • 做网站的图片要求大小郑州今日重大新闻
  • 广州联享网站建设公司怎么样发软文是什么意思
  • 旅游网站建设需求说明书收录优美的图片
  • 建设网站要在需求海口seo快速排名优化
  • 推进门户网站建设 用好用活廊坊seo排名优化
  • 海沧网站制作网上营销方法
  • 学校语言文字网站建设百度指数在哪里看
  • 东莞快速网站制作哪家强百度搜索竞价
  • 网站开发国内外研究现状cps推广平台有哪些
  • dw做网站怎么加视频石家庄网络seo推广
  • 苏州抖音代运营公司网络推广的调整和优化
  • 请人做网站合同整合营销是什么
  • 如何买域名发布网站seo入门培训学校
  • 什么是网站版式大地seo视频
  • 外贸建站哪家强外贸网站怎么做公司网页制作教程
  • 中企动力做的网站升级收费免费制作自己的网页