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

下载本文档

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

文档简介

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

2、比较少。安装之前:1、准备工作:nginx1) apache是停止的,释放80端口2)添加一个普通用户,出于安全的目的使用这个普通用户去运行# useradd -M -s /sbin/nologin www默认使用的是nobody 这个用户。2、开始安装rootlocalhost lnmp# ls nginx-x.tar.gznginx-x.tar.gzrootlocalhost lnmp# tar zxvf nginx-x.tar.gz -C /usr/local/src/专业.专注.word可编辑.安装nginx所需的软件包:pcre-8.10.tar.gznginx-0.8.46.tar

3、.gz(1) PCRE: Perl 库,Perl Compatible Regular Expressions支持正则表达式rootlocalhost nginx# tar zxvf pcre-8.10.tar.gzrootlocalhost nginx# cd pcre-8.10rootlocalhost pcre-8.10# lsrootlocalhost pcre-8.10# ./configurerootlocalhost pcre-8.10# makerootlocalhost pcre-8.10# make install(2)安装 nginxrootlocalhost nginx

4、# ls nginx-0.8.46.tar.gznginx-0.8.46.tar.gzrootlocalhost nginx# tar zxvf nginx-0.8.46.tar.gzrootlocalhost nginx-0.8.46# ./configure -user=www -group=www专业.专注.word可编辑.-prefix=/usr/local/nginx -with-http_stub_status_module -with-http_ssl_module-user-group-prefix-with-http_stub_status_module状态模块-with-h

5、ttp_ssl_module支持 httpsyum install -y openssl-develrootlocalhost nginx-0.8.46# makerootlocalhost nginx-0.8.46# make installrootlocalhost nginx-0.8.46# cd /usr/local/nginx/rootlocalhost nginx# lsconf html logs sbin启动服务:rootlocalhost nginx# ./sbin/nginx -c conf/nginx.confrootlocalhost nginx# netstat -a

6、ntp | grep 80tcp00 :80:* LISTEN 19449/nginx.conf专业.专注.word可编辑.访问:http:53/Welcome to nginx! OK解读配置文件:rootlocalhost conf# pwd/usr/local/nginx/confrootlocalhost conf# vim nginx.conf1user www;worker_processes 1; #开启的进程数,与 CPU的核数一致,查看CPU的信息:rootlocalhost html# cat /proc/cpuinfo#error_log logs/error.log;错

7、误日志#error_loglogs/error.lognotice;#error_loglogs/error.loginfo;redhat 5man 5 syslog.confredhat 6man 5 rsyslog.conf ?专业.专注.word可编辑.#pidlogs/nginx.pid; * *events use epoll;#指定nginx使用高效的工作模式worker_connections 1024;#每个进程能够处理的最大连接数能够处理的最大连接数=worker_processes x worker_connectionsuse epoll; 指定nginx的工作模式默认使

8、用的是select和pollepoll 2.6内核之后,某些发行版,比如SUSE、redhat支持epoll模型uname -r2.6.18-194.el5linux 和redhat 和 windows 有没有可比性?其他的发行版,要想使用高效模式:kqueue BSD系列MacOS等cat /etc/issueRed Hat Enterprise Linux Server release 5.5 (Tikanga)专业.专注.word可编辑.18 http 192022-26282931323436373839404142includemime.types;#文件的扩展名和文件类型defau

9、lt_type application/octet-stream; #文件的类型默认是二进制访问日志sendfileon; #开启高效的文件传输模式#tcp_nopush on;#防止网络阻塞#keepalive_timeout 0;#长连接的超时时间,秒keepalive_timeout65;#gzip on;#开启gzip压缩传输数据server listen80;server_name localhost;#charset koi8-r; # 字符集#access_log logs/host.access.log main;专业.专注.word可编辑.43location / rooth

10、tml; = documentrootindexindex.html index.htm;页面文件的名字虚拟主机:基于域名的虚拟主机。FQDNDocumentroot/htdocs/ww1/htdocs/ww2default/htdocs/default日志迁移:从 /usr/local/nginx/logs - /logs(raid0)# mkdir -p /htdocs/ww1,ww2,default -v注意权限: www 进去 xrootlocalhost conf# cd /htdocs/ww1rootlocalhost ww1# echo index.html专业.专注.word可

11、编辑.rootlocalhost ww1# cd ./ww2rootlocalhost ww2# echo index.htmlrootlocalhost ww2# cd ./default/rootlocalhost default# echo index.html测试配置文件是否正确:rootlocalhost nginx# ./sbin/nginx -tthe configuration file /usr/local/nginx/conf/nginx.conf syntax is okconfiguration file /usr/local/nginx/conf/nginx.conf

12、 test is successful重启:用kill命令给nginx的pid传递一个信号,让它重新读取配置文件rootlocalhost nginx# cat logs/nginx.pid19449 nginx的平滑重启:rootlocalhost nginx# kill -HUP 19449客户端测试:vim /etc/hosts添加专业.专注.word可编辑.5353打开浏览器: HYPERLINK / / HYPERLINK / / HYPERLINK 53/ 53/nginx的日志管理错误日志:nginx出问题,查看错误日志,排错访问日志:查看有哪些客户端来访问自己log_forma

13、t ww1 $remote_addr - $remote_user $time_local $request$status $body_bytes_sent $http_referer$http_user_agent $http_x_forwarded_for;access_log logs/ww1.log ww1;专业.专注.word可编辑.log_format 指定日志的格式log_format name format$remote_addr 和 $http_x_forwarded_for : t己录 ip 地址 *$remote_user :记录客户端的用户名称$time_local :

14、记录访问时间和时区 *$request :记录请求的URL和HTTP协议$status :记录请求状态$body_bytes_sent :记录发送给客户端的文件的主体内容的大小$http_referer :记录从哪个页面链接过来的$http_user_agent :记录客户端浏览器的信息access_log指定日志的存放路径问题:日志轮替写一个日志轮替的脚本,结合计划任务。1周替换一个新的日志文件?农场和斗地主专业.专注.word可编辑.斗地主:server ip : 21rootlocalhost s1# yum install -y httpd mysql-server php php-m

15、ysqlrootlocalhost html# pwd/var/www/htmlrootlocalhost html# ls ddzrootlocalhost html# chmod -R 777 ddz/rootlocalhost html# /etc/init.d/mysqld startmysql create database ddz;mysql grant all on ddz.* to ddzuserlocalhost identified by 123456;mysql flush privileges;rootlocalhost html# vim +391 /etc/http

16、d/conf/httpd.confDirectoryIndex index.php index.html index.html.var专业.专注.word可编辑.rootlocalhost html# /etc/init.d/httpd restart网页安装: HYPERLINK 21/ddz/install.php 21/ddz/install.php服务器:localhost数据库:ddzDB 帐号:ddzuserDB 密码:123456QQ农场:server ip : 21rootlocalhost s1# yum install -y httpd mysql-server php p

17、hp-mysqlrootlocalhost Desktop# lsflash-plugin-5-release.i386.rpm qq 农场.ziprootlocalhost Desktop# unzip qq 农场.zip -d /var/www/html/rootlocalhost html# pwd/var/www/html专业.专注.word可编辑.rootlocalhost html# mv upload/ qqrootlocalhost html# lsddz qqrootlocalhost html# chmod -R 777 qqrootlocalhost html# /etc

18、/init.d/mysqld startmysql create database qq;mysql grant all on qq.* to qquserlocalhost identified by 123456;mysql flush privileges;rootlocalhost html# vim +391 /etc/httpd/conf/httpd.confDirectoryindex index.php index.html index.html.varrootlocalhost html# /etc/init.d/httpd restartrootlocalhost qq#

19、pwd/var/www/html/qqrootlocalhost qq# mysql qq 静态页面 index.html/htdocs/ww1/index.htmllocation /index.html写在虚拟主机里:location /index.html deny all;写完了别忘了重启服务。专业.专注.word可编辑.location /index.html return 404;)location /.*.html$ return 404;)rootlocalhost ww1# pwd/htdocs/ww1rootlocalhost ww1# lsindex.htmlrootlo

20、calhost ww1# echo 123 123.htmlrootlocalhost ww1# echo 456 456.htmllocation /123.html rewrite A/123.html$ HYPERLINK /456.html /456.html;)index.jsp asp?asdhka903249871fsdaindex.jsp?.*专业.专注.word可编辑.反向代理+负载均衡软彳7层 负载均衡:nginx L7SW( layer 7 )配置nginx :http (upstream uplook #定义一个 server_pool , 里面有一组服务器server

21、 02;#这是 3 个 apache 的 ipserver 03;server 04;server listen80;location / proxy_passhttp:uplook;timeoutproxy_next_upstream http_500 http_502 http_503 error invalid_header;专业.专注.word可编辑.include /usr/local/nginx/conf/proxy.conf;rootlocalhost conf# vim proxy.conf proxy_redirect off;proxy_set_header Host $host;#设置由后端服务器获取用户的主机名proxy_set_header X-Real_IP $remote_addr;#设置后端服务器获取用户的真实ip地址proxy_set_header X-Forwarded-Fo

温馨提示

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

评论

0/150

提交评论