Nginx 简介
Nginx是一个高性能的Web 服务器,同时是一个高效的反向代理服务器,它还是一个IMAP/POP3/SMTP
代理服务器。
由于Nginx采用的是事件驱动的架构,能够处理并发百万级别的tcp连接,高度的模块化设计和自由的BSD许可,使得Nginx有着非常丰富的第三方模块。比如Openresty、API网关Kong。
Nginx的优点
- 高并发响应性能非常好,官方Nginx处理静态文件并发5w/s
- 反向代理性能非常强。(可用于负载均衡)
- 内存和cpu占用率低。(为Apache的1/5-1/10)
- 对后端服务有健康检查功能。
- 支持PHP cgi方式和fastcgi方式。
- 配置代码简洁且容易上手。
Nginx的安装
-
工具安装
yum install gcc-c++
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel -
软件安装
wget -c https://nginx.org/download/nginx-1.10.1.tar.gz
tar -zxvf nginx-1.10.1.tar.gz
cd nginx-1.10.1
./configure -
编译安装
make
make install
whereis nginx ## 查找安装路径 -
启动 nginx
./usr/local/nginx/sbin/nginx
http://192.168.100.58/ -
nginx 环境变量配置 不需要在指定目录执行命令
export PATH=$PATH:/usr/local/nginx/sbin
source /etc/profile ## 让配置立刻生效
Nginx常用命令
-
启动nginx
nginx
启动结果显示nginx的主线程和工作线程,工作线程的数量跟nginx.conf中的配置参数worker_processes有关 -
平滑启动nginx
kill -HUP cat /var/run/nginx.pid
或者
nginx -s reload -
强制停止nginx
pkill -9 nginx
检查对nginx.conf文件的修改是否正确
nginx -t -
停止nginx的命令
nginx -s stop或者pkill nginx -
查看nginx的版本信息
nginx -v -
查看完整的nginx的配置信息
nginx -V
-nginx 故障解决
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nginx -s reload
nginx 卸载
- 卸载:
yum remove nginx - 删除nginx目录
whereis nginx
rm -rf /opt/nginx
(rm -rf /usr/local/nginx)
nginx 负载均衡配置
新建 fzjh.conf
启动nginx: /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/fzjh.conf
user nobody;
worker_processes 4;
events{
worker_connections 1024;
}
http{
upstream test.com {
server 192.168.100.11:3013 weight=1;
server 192.168.100.58:8080 weight=2;
}
server{
listen 9080;
location / {
proxy_pass http://test.com;
}
}
}
gitbook 使用【自己搭建博客】
需要先安装 nodejs
1.npm -g install gitbook-cli
npm install -g gitbook-cli
2.gitbook init
3.gitbook serve