Web服务器ngin虚拟主机与反向代理_第1页
Web服务器ngin虚拟主机与反向代理_第2页
Web服务器ngin虚拟主机与反向代理_第3页
已阅读5页,还剩17页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、Web服务器nginx虚拟主机与反向代理web 服务器 -nginxweb服务器简介:apache , web服务器:访问网页,查找、浏览信息。蜘蛛程序一网络爬虫常见的web服务器:apachelighttpdn gi nxtomcatIIS介绍nginx :高性能的http服务器和反向代理服务器(web加速),运行在类unix和windows上为什么选择 nginx ?处理速度快,占用的资源少apache里的模块是动、静结合;在nginx里面,都是静态的。支持热部署可以7x24不间断运行书写的代码质量很高,也很规范问题:俄国人写的,一些官方资料,文档比较少。安装之前:1、准备工作:1) ap

2、ache是停止的,释放80端口nginx2) 添加一个普通用户,出于安全的目的使用这个普通用户去运行# useradd -M -s /sbin/no logi n www默认使用的是nobody 这个用户。2、开始安装rootlocalhost l nmp# tar zxvf n gi nx-x.tar.gz -C /usr/local/src/安装nginx所需的软件包支持正则表达式(1) PCRE: Perl 库,Perl Compatible Regular Expressionsrootlocalhost nginx# cd pcre-8.10rootlocalhost pcre-8.

3、10# lsrootlocalhost pcre-8.10# ./c on figurerootlocalhost pcre-8.10# makerootlocalhost pcre-8.10# make in stall(2)安装 nginxrootlocalhostngi nx-0.8.46#./c on figure-user=www-group=www-prefix=/usr/local/ngi nx-with-http_stub_status_module -with-http_ssl_module-user-group-prefix-with-http_stub_status_mo

4、dule状态模块-with-http_ssl_module支持 httpsyum in stall -y ope nssl-develrootlocalhost nginx-0.8.46# makerootlocalhost ngi nx-0.8.46# make in stallrootlocalhost nginx-0.8.46# cd /usr/local/nginx/rootlocalhost ngin x# lsconf html logs sbin启动服务:rootlocalhost n gi nx# ./sb in/nginx -c conf/ngin x.c onfrootlo

5、calhost nginx# n etstat -antp | grep 80tcp00 :80:* LISTEN 19449/ngi nx.c onf访问:Welcome to nginx! OK解读配置文件:rootlocalhost conf# pwd/usr/local/nginx/confrootlocalhost conf# vim ngin x.c onf12 user www;3 worker_processes 1; #开启的进程数,与 CPU的核数一致,查看CPU的信息:rootlocalhost html# cat /proc/cpu info

6、5 #error_log logs/error.log;错误日志6 #error_log logs/error.log no tice;7 #error_log logs/error.log info;redhat 5man 5 syslog.c onfredhat 6man 5 rsyslog.c onf ?9 #pidlogs/ngi nx.pid;*12 events 13 use epoll;#指定nginx使用高效的工作模式14 worker_connections1024;#每个进程能够处理的最大连接数15 能够处理的最大连接数=worker_processes x worker_

7、c onnectionsuse epoll; 指定nginx的工作模式默认使用的是select和pollepoll 2.6内核之后,某些发行版,比如SUSE、redhat支持epoll模型# un ame -rlinux 和redhat 和 windows 有没有可比性?其他的发行版,要想使用高效模式:kqueue BSD系列MacOS等# cat /etc/issueRed Hat En terprise Li nux Server release 5.5 (Tika nga)18http 192022-26282931323436373839404142in eludemime.types

8、;#文件的扩展名和文件类型default_type applicatio n/octet-stream; #文件的类型默认是二进制访问日志sen dfileon;#开启高效的文件传输模式#tcp_nopushon; #防止网络阻塞#keepalive_timeout 0;#长连接的超时时间,秒keepalive_timeout65;#gzip on;#开启gzip压缩传输数据server liste n80;server_ namelocalhost;#charset koi8-r; # 字符集#access_log logs/host.access .log main;4344 locati

9、on / 45 root html; = docume ntroot46 in dexin dex.html in dex.htm;页面文件的名字47 虚拟主机:基于域名的虚拟主机。FQDNDocume ntrootww1. ngi /htdocs/ww1ww2. ngi /htdocs/ww2default/htdocs/default- /logs(raidO)日志迁移: 从 /usr/local/nginx/logs# mkdir -p /htdocs/ww1,ww2,default -v注意权限: www 进去 xrootlocalhost conf# cd /htdocs/ww1ro

10、otlocalhost ww1# echo ww1. ngin in dex.htmlrootlocalhost ww1# cd ./ww2rootlocalhost ww2# echo ww2. ngin in dex.htmlrootlocalhost ww2# cd ./default/rootlocalhost default# echo default .ngin in dex.html测试配置文件是否正确:rootlocalhost ngin x# ./sb in/nginx-tthe configuration file /usr/local/nginx/conf/nginx.c

11、onf syntax is okconfiguration file /usr/local/nginx/conf/nginx.conf test is successful重启:用kill命令给nginx的pid传递一个信号,让它重新读取配置文件rootlocalhost n gi nx# cat logs/ngin x.pid19449nginx的平滑重启:rootlocalhost nginx# kill -HUP 19449客户端测试:vim /etc/hosts添加53ww1. ngi 53ww2. ngi 打开浏览器:. ngi ww1.

12、ngin . ngin ww2. ngin /default .ngin nginx的日志管理错误日志:nginx出问题,查看错误日志,排错访问日志:查看有哪些客户端来访问自己log_format ww1 $remote_addr - $remote_user $time_local $request$status $body_bytes_se nt $http_referer$http_user_age nt $http_x_forwarded_for;access_log logs/ww1.log ww1;1. Iog_format指定日志的格式log_format n ame forma

13、t$remote_addr 禾口 $http_x_forwarded_for: i己录 ip 地址 *$remote_user :记录客户端的用户名称$time_local :记录访问时间和时区*$request :记录请求的URL和HTTP协议$status :记录请求状态$body_bytes_sent:记录发送给客户端的文件的主体内容的大小$http_referer :记录从哪个页面链接过来的$http_user_age nt :记录客户端浏览器的信息2. access_log指定日志的存放路径问题:日志轮替写一个日志轮替的脚本,结合计划任务。1周替换一个新的日志文件?农场和斗地主斗地主

14、:server ip : rootlocalhost si# yum in stall -y httpd mysql-server php php-mysqlrootlocalhost html# pwd/var/www/htmlrootlocalhost html# lsddzrootlocalhost html# chmod -R 777 ddz/rootlocalhost html# /etc/i nit.d/mysqld startmysql create database ddz;mysql grant all on ddz.* to ddzuserlocalhost identif

15、ied by 123456;mysql flush privileges;rootlocalhost html# vim +391 /etc/httpd/c on f/httpd.co nfrootlocalhost html# /etc/i nit.d/httpd restart网页安装:服务器:localhost数据库:ddzDB 帐号:ddzuserDB 密码:123456QQ农场:server ip : rootlocalhost s1# yum in stall -y httpd mysql-server php php-mysqlrootlocalhost Desktop# lsf

16、lash-plugin-5-release.i386.rpmqq 农场.ziprootlocalhost Desktop# unzip qq 农场.zip -d /var/www/html/rootlocalhost html# pwd/var/www/htmlrootlocalhost html# mv upload/ qqrootlocalhost html# Isddz qqrootlocalhost html# chmod -R 777 qqrootlocalhost html# /etc/i nit.d/mysqld startmysql create datab

17、ase qq;mysql grant all on qq.* to qquserlocalhost identified by 123456;mysql flush privileges;rootlocalhost html# vim +391 /etc/httpd/c on f/httpd.co nfrootlocalhost html# /etc/i nit.d/httpd restartrootlocalhost qq# pwd/var/www/html/qqrootlocalhost qq# mysql qq 静态页面 index.html/htdocs/ww1/i ndex.html

18、location /index.html写在虚拟主机里:location /index.html deny all;写完了别忘了重启服务。location /index.html return 404;location /.*.html$ return 404;rootlocalhost ww1# pwd/htdocs/ww1rootlocalhost ww1# lsin dex.htmlrootlocalhost ww1# echo 123 123.htmlrootlocalhost ww1# echo 456 456.htmllocation /123.html rewrite A/123

19、.html$ . ngi in dex.jsp asp?asdhka903249871fsdain dex.jsp?.*反向代理+负载均衡软件7层 负载均衡:nginxL7SW( layer 7 )酉己置nginx :http upstream uplook #定义一个 server_pool , 里面有一组服务器server 02;#这是 3 个 apache 的 ipserver 03;server 04;server liste n80;locati on / proxy_pass;timeoutproxy_ next_u

20、pstreamhttp_500 http_502 http_503 errorin valid_header;in elude /usr/local/ngi nx/con f/proxy.c onf;rootlocalhost conf# vim proxy.c onfproxy_redirect off;proxy_set_header Host $host;#设置由后端服务器获取用户的主机名ip地址proxy_set_header X-Real_IP $remote_addr;#设置后端服务器获取用户的真实proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;#设置有后端服务器获取代理者的真实ipclie nt_body_buffer_size 128k;#用于指疋客户端请求主体缓冲区大小proxy_c onn

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论