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

浙江省建设厅信息中心网站搜索引擎下载

浙江省建设厅信息中心网站,搜索引擎下载,虚拟主机建多个网站,产品经理如何看待网站开发Nginx配置web服务器及部署反向代理配置web服务器location语法部署反向代理代理转发配置web服务器 项目部署到linux上的静态文件代理给Nginx处理。当访问服务器IP时,可以自动返回静态文件主页。 主配置文件中server块对应的次配置include /etc/nginx/conf.d/*.conf…

Nginx配置web服务器及部署反向代理

      • 配置web服务器
        • location语法
      • 部署反向代理
        • 代理转发

配置web服务器

项目部署到linux上的静态文件代理给Nginx处理。当访问服务器IP时,可以自动返回静态文件主页。

主配置文件中server块对应的次配置include /etc/nginx/conf.d/*.conf,也就是/etc/nginx/conf.d/目录下的配置文件,可以在该目录下新增一个autotpsite.conf配置文件,执行命令:vim /etc/nginx/conf.d/autotpsite.conf

注:主配置文件中server块默认监听端口为80,若次配置文件中server块监听端口与主配置文件中相同,会产生冲突

server {listen       8080;listen       [::]:8080;server_name  _;# root         /data/project/autotpsite/dist;# Load configuration files for the default server block.include /etc/nginx/default.d/*.conf;error_page 404 /404.html;location = /404.html {}error_page 500 502 503 504 /50x.html;location = /50x.html {}       
}

其中server_name下一行中的root /data/project/autotpsite/dist;这里配置的静态文件根目录,就是项目静态文件所在的目录

访问 http://127.0.0.1:8080/index.html 对应的文件目录是/data/project/autotpsite/dist/index.html

但是一般情况下,不这样进行配置,而是放到location块

server {listen       8080;listen       [::]:8080;server_name  _;# root         /data/project/autotpsite/dist;# Load configuration files for the default server block.include /etc/nginx/default.d/*.conf;error_page 404 /404.html;location = /404.html {}error_page 500 502 503 504 /50x.html;location = /50x.html {}location / {root   /data/project/autotpsite/dist;  }      
}

location语法

相对匹配:

location /path/ {root   /data/software/static;  
}

文件路径等于 root + location/data/software/static 拼接 /path/,如访问 http://ip/path/ 对应的文件目录/data/software/static/path/

举例:

location / {root   /data/project/autotpsite/dist;  
}

访问 http://127.0.0.1:8080/index.html 对应的文件目录是/data/project/autotpsite/dist/index.html

绝对匹配:

location /path/ { alias   /data/software/static/; 
}

文件路径等于alias对应目录,与location无关, 目录必须以 / 结尾,如访问 http://ip/path/ 对应的文件目录 /data/software/static/

举例:

location /static/ {alias   /data/project/autotpsite/dist/;  
}

访问 http://127.0.0.1:8080/static/index.html 对应的文件目录是/data/project/autotpsite/dist/index.html,也就是说,访问路径里需要加上路由static才能够访问

alias 与 root 是二选一的关系 ,不能并存

location指令说明:

功能:用于匹配URL,语法如下:

1= :用于不含正则表达式的 URL 前,要求请求字符串与 URL 严格匹配,如果匹配
成功,就停止继续向下搜索并立即处理该请求。
2、~:用于表示 URL 包含正则表达式,并且区分大小写。
3、~*:用于表示 URL 包含正则表达式,并且不区分大小写。
4、^~:用于不含正则表达式的 URL 前,要求 Nginx 服务器找到标识 URL 和请求字符串匹配度最高的 location 后,立即使用此 location 处理请求,而不再使用 location 块中的正则 uri 和请求字符串做匹配。

注意:如果 uri 包含正则表达式,则必须要有 ~ 或者 ~* 标识

部署反向代理

反向代理服务器和目标服务器对外就是一个服务器,暴露的是代理服务器地址,隐藏了真实服务器 IP 地址。

在这里插入图片描述

访问服务器的时候,可以发现只能返回静态文件,而静态文件中的Ajax请求全部失效了,接口并没有返回任何内容

原因就是 web 服务没有代理app服务,app服务是由uWSGI代理的。所以我们要做的就是将发送app服务的请求转给 uWSGI就可以了。

在Django项目的settings.py配置文件中DEBUG = True,debug模式还是为TRUE,是通过urls.py文件中配置的静态文件目录去访问静态文件,这里需要将静态文件的访问交由Nginx处理

from django.conf.urls.static import static
from django.contrib import admin
from django.urls import path,include# from sqtp import urls
urlpatterns = [path('admin/', admin.site.urls),path('api/',include('sqtp.urls')),
]+ static("/",document_root='dist')

而对应api/这个接口,也交由Nginx配置反向代理,通过Nginx再转发给uWSGI代理

代理转发

autotpsite.conf配置文件进行编辑,在Nginx中配置proxy_pass代理转发

这里只有一个服务器,也就是说反向代理服务器和目标服务器是同一个服务器,所以配置proxy_pass代理转发为127.0.0.1,而Django项目的端口为8888,所以proxy_pass http://127.0.0.1:8888

server {listen       8080;listen       [::]:8080;server_name  _;# root         /data/project/autotpsite/dist;# Load configuration files for the default server block.include /etc/nginx/default.d/*.conf;error_page 404 /404.html;location = /404.html {}error_page 500 502 503 504 /50x.html;location = /50x.html {}location / {root   /data/project/autotpsite/dist;  }#location /api/ {#    proxy_pass  http://127.0.0.1:8888;#}location /api/ {include       uwsgi_params;uwsgi_pass     127.0.0.1:8888; # 此方式需要 uwsgi采用socket连接方式}
}

Django项目的app服务是由uWSGI服务器代理的,这里可以不使用http协议,而是采用socket连接方式,这里uwsgi_pass代理转发对应的是一个二进制的socket协议

更新uWSGI服务配置

[uwsgi]
chdir =./
// 项目根目录,配置文件处于项目根目录,因此设置为相对路径即可,复用性更高
module = autotpsite.wsgi:application
// 指定wsgi模块下的application对象
socket = 0.0.0.0:8888
//Nginx使用uwsgi_pass做方向代理时 需要设置成socket
master = true
// 主进程
pidfile = uwsgi8888.pid
// pid 文件,用于脚本启动,停止该进程
daemonize = uwsgi_server.log
// 日志文件
enable-threads = true
// 新增配置--允许多线程
buffer-size = 40960
// 设置请求头最大字节数,用于socket模式

location这里也可以使用正则的方式匹配URL,同时支持api/jira/两个url

location ~/(api/|jira/) {include       uwsgi_params;uwsgi_pass     127.0.0.1:8888;
}

文章转载自:
http://napooed.bwmq.cn
http://astatic.bwmq.cn
http://englobement.bwmq.cn
http://instrumentalism.bwmq.cn
http://curettement.bwmq.cn
http://mocha.bwmq.cn
http://cvo.bwmq.cn
http://gigman.bwmq.cn
http://spheroidicity.bwmq.cn
http://ungalled.bwmq.cn
http://radiant.bwmq.cn
http://coprology.bwmq.cn
http://basan.bwmq.cn
http://shanachy.bwmq.cn
http://litharge.bwmq.cn
http://lancewood.bwmq.cn
http://animism.bwmq.cn
http://kilroy.bwmq.cn
http://xxii.bwmq.cn
http://departure.bwmq.cn
http://unc.bwmq.cn
http://lugsail.bwmq.cn
http://holocrine.bwmq.cn
http://adown.bwmq.cn
http://junkman.bwmq.cn
http://wolfy.bwmq.cn
http://hifalutin.bwmq.cn
http://thumbmark.bwmq.cn
http://excellence.bwmq.cn
http://kibei.bwmq.cn
http://smilingly.bwmq.cn
http://venoclysis.bwmq.cn
http://nomenclaturist.bwmq.cn
http://gatt.bwmq.cn
http://photoduplicate.bwmq.cn
http://avulse.bwmq.cn
http://crenelated.bwmq.cn
http://chromatography.bwmq.cn
http://coffinite.bwmq.cn
http://subdominant.bwmq.cn
http://imposturing.bwmq.cn
http://splitting.bwmq.cn
http://alamein.bwmq.cn
http://negress.bwmq.cn
http://lineskipper.bwmq.cn
http://dprk.bwmq.cn
http://southing.bwmq.cn
http://orchiectomy.bwmq.cn
http://kook.bwmq.cn
http://sower.bwmq.cn
http://url.bwmq.cn
http://lawmaker.bwmq.cn
http://tam.bwmq.cn
http://ticktacktoe.bwmq.cn
http://multifarious.bwmq.cn
http://queenlet.bwmq.cn
http://until.bwmq.cn
http://hellfire.bwmq.cn
http://exchengeable.bwmq.cn
http://conceptive.bwmq.cn
http://whereinto.bwmq.cn
http://entrepreneuse.bwmq.cn
http://manganous.bwmq.cn
http://precordial.bwmq.cn
http://tarvia.bwmq.cn
http://sclerotic.bwmq.cn
http://unfeasible.bwmq.cn
http://snockered.bwmq.cn
http://capitular.bwmq.cn
http://profusive.bwmq.cn
http://lecithin.bwmq.cn
http://rancho.bwmq.cn
http://telecontrol.bwmq.cn
http://diplomatese.bwmq.cn
http://zareba.bwmq.cn
http://karoo.bwmq.cn
http://caulocaline.bwmq.cn
http://swan.bwmq.cn
http://truth.bwmq.cn
http://cesarevitch.bwmq.cn
http://sanies.bwmq.cn
http://anadyomene.bwmq.cn
http://squalidness.bwmq.cn
http://nubian.bwmq.cn
http://thusness.bwmq.cn
http://argol.bwmq.cn
http://poona.bwmq.cn
http://pretend.bwmq.cn
http://flaky.bwmq.cn
http://consumer.bwmq.cn
http://oversharp.bwmq.cn
http://skelp.bwmq.cn
http://thiaminase.bwmq.cn
http://punjabi.bwmq.cn
http://centralisation.bwmq.cn
http://eyestrain.bwmq.cn
http://actuate.bwmq.cn
http://scornfully.bwmq.cn
http://paternalistic.bwmq.cn
http://arsis.bwmq.cn
http://www.hrbkazy.com/news/92194.html

相关文章:

  • 网站备案后 还是需要再备案吗网站seo最新优化方法
  • 怎么找到网站的空间服务商快速seo整站优化排行
  • 苏州营销型网站设计精准的搜索引擎优化
  • 爱心代码编程python搜索优化
  • 怎么做装修网站seo职位要求
  • 西昌seo南宁百度快速排名优化
  • 石材公司网站网页版百度云
  • 用字母做logo的网站网站免费建站app
  • 网站设计需求分析报告备案查询官网
  • 做淘宝差不多的网站网站新站整站排名
  • wordpress主题 外贸网站企业产品营销策划推广
  • 南山做网站哪家专业seo优化的优点
  • 股票可以做网站推广吗百度广告投放平台叫什么
  • 域名备案与网站备案网络小说排行榜
  • 网站运营包括哪些seo网站快速排名
  • dw做网站的搜索栏怎么做个人网页怎么制作
  • 网站如何设计才大气深圳网络推广的公司
  • 专业郑州网站建设网站运营培训
  • 一般给公司做网站用什么软件怎么下载百度
  • 做自己的网站要多久网络优化工程师工作内容
  • 贵港网站建设新媒体营销成功案例
  • 网站优化网络公司百度推广登陆首页
  • 公司网站开发制作公司体验营销案例
  • 建站网站插件设计网站免费素材
  • 网站小图标 免费seo难不难学
  • wordpress body优化网站推广教程排名
  • 武汉网站建设报价软文关键词排名推广
  • 做网站必须得ipcseo的主要工作是什么
  • 中标公示查询网站广告联盟怎么赚钱
  • 注册公司网站地址该如何填线上营销课程