nginx的安装及使用 nginx apache nginx php nginx rewrite

php中文网
发布: 2016-07-29 08:48:58
原创
1083人浏览过
阻塞调用:事件没有准备好,那就只能等了,等事件准备好了,你再继续吧。
阻塞调用会进入内核等待,cpu就会让出去给别人用了,对单线程的worker来说,显然不合适,当网络事件越多时,大家都在等待呢,cpu空闲下来没人用,cpu利用率自然上不去了,更别谈高并发了。
异步非阻塞:异步非阻塞的事件处理机制,具体到系统调用就是像select/poll/epoll/kqueue这样的系统调用。
它们提供了一种机制,让你可以同时监控多个事件,调用他们是阻塞的,但可以设置超时时间,在超时时间之内,如果有事件准备好了,就返回。
tar -zxvf nginx.tar.gz
./configure
linux 安装gcc,gcc-c++
yum -y install gcc gcc-c++ autoconf automake
安装pcre
yum -y install pcre pcre-devel
安装zlib
yum -y install zlib zlib-devel
make
make install 
启动nginx 服务器
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
停止nginx服务器
1.从容停止
kill -QUIT 15369
2.快速停止
kill -TERM 15417
kill -INT 15417
3.强制停止
pkill -9 nginx
4.验证配置文件的正确性
./nginx -t
./nginx -t -c /usr/local/nginx/conf/nginx.conf
5.nginx 重启
./nginx -s reload(进入到所在目录)
kill -HUP 15446
6.USR1:切换日志文件
  USR2:平滑升级可执行进程
  WINCH:从容关闭工作进程(kill -WINCH 2255)
7.查看版本
./nginx -V
#设置用户
#user nobody
#工作衍生进程数(等于cpu的核数或2倍的核数)
worker_processes 6;
#设置pid存放的路径
#pid logs/nginx.pid;
//最大连接数
events {
    worker_connections  1024;
}
#开启gzip 开启(用户访问的是压缩过的文件(原来的30%))
#gzip on 
#设置字符编码
charset koi8-r;
charset gb2312;
nginx配置文件的抽象(实例)
user nobody;
worker_processes 4;
events{
worker_connections 1024;
}
http{
server{
listen 192.168.1.7:80;
server_name 192.168.1.7;
access_log logs/server1.access.log.combined;
location /
{
index index.html index.htm;
root html/server1;
}
}
server{
listen 192.168.1.8:80;
  server_name 192.168.1.17;
access_log logs/server2.access.log.combined;
location /
{
index index.html index.htm;
root html/server2;
}
}
}
设置主机的ip地址和子网掩码
ifconfig eth1 192.168.1.10 netmask 255.255.255.0
设置虚拟主机(子服务器)的ip地址和广播地址和子网掩码
ifconfig eth1:1 192.168.1.7 broadcast 192.168.1.255 netmask 255.255.255.0
虚拟主机的配置:在配置好了ip地址之后,我们需要将对应的ip地址与对应的虚拟主机建立联系
log_format指令是用来设置nginx服务器的日志文件的记录格式
log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
 
remote_addr : ip地址
remote_user : 用户
request     : 请求的网址
status      : 状态
body_bytes_sent : 传送的字节数
http_referer: 原页面
http_user_agent : 浏览器(客户端)
http_x_forwarded_for:类似ip
//修改nginx默认的配置文件
vi /usr/local/nginx/conf/nginx.conf
access_log 存储路径
/*****************nginx 实现负载均衡*********************/
   user nobody;
   worker_processes 4;
   events{
          worker_connections 1024;
   }
   http{
           upstream myproject{
ip_hash;  
                   server 115.239.210.27;
                   server 180.96.12.1;
                  server 42.156.140.7;
                  server 140.205.230.49;
                  server 122.225.67.253;
          }
          server{
                  listen 8080;
                  location /
                  {
                          proxy_pass http://myproject;
                  }
          }
  
  
  }
 
/*****************nginx 实现负载均衡*********************/

以上就介绍了nginx的安装及使用,包括了nginx方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

PHP速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
相关标签:
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号