一、安装Nginx
1、准备工作
(1)打开虚拟机,使用远程连接工具连接 linux 操作系统
(2)到 nginx 官网下载软件
http://nginx.org/
2、开始进行 nginx 安装
(1)安装 pcre 依赖
第一步 联网下载 pcre 压缩文件依赖
wget http://downloads.sourceforge.net/project/pcre/pcre/8.37/pcre-8.37.tar.gz
第二步 解压压缩文件
使用命令 tar –xvf pcre-8.37.tar.gz
第三步./configure 完成后,回到 pcre 目录下执行 make,最后执行 make install
查看pcre依赖是否安装成功:pcre-config --version
(2)安装 openssl 、zlib 、 gcc 依赖
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
(3)安装 nginx
* 使用命令解压
* ./configure
* make && make install
进入目录 /usr/local/nginx/sbin/nginx 启动服务
安装后,不能访问的,需要对防火墙进行设置
也可以直接关闭防火墙,并防止自启(在练习模式中)
//关闭防火墙&&防火墙自启 systemctl stop firewalld && systemctl disable firewalld //安装Iptables管理工具&&启动Iptables&&设为Iptables开机自启&&清空Iptables规则&&保存Iptables默认规则 yum -y install iptables-services && systemctl start iptables && systemctl enable iptables&& iptables -F && service iptables save
① 查看开放的端口
firewall-cmd --list-all

② 设置开放的端口号
firewall-cmd --add-service=http –permanent
firewall-cmd --add-port=80/tcp --permanent
③ 设置之后需要重启防火墙
firewall-cmd --reload

④ 访问成功

二、Nginx常用命令
进入 nginx 目录中: cd /usr/local/nginx/sbin
1、查看 nginx 版本号
./nginx -v
2、启动 nginx
./nginx
查看是否启动成功:ps -ef|grep nginx

3、停止 nginx
./nginx -s stop
4、重新加载 nginx
./nginx -s reload
三、nginx.conf配置文件
1、位置
vim /usr/local/nginx/conf/nginx.conf
2、配置文件中的内容(包含三部分)
(1)全局块:配置服务器整体运行的配置指令
从配置文件开始到 events 块之间的内容,主要会设置一些影响 nginx 服务器整体运行的配置指令,主要包括配
置运行 Nginx 服务器的用户(组)、允许生成的 worker process 数,进程 PID 存放路径、日志存放路径和类型以
及配置文件的引入等。
比如上面第一行配置的:
这是 Nginx 服务器并发处理服务的关键配置,worker_processes 值越大,可以支持的并发处理量也越多,但是
会受到硬件、软件等设备的制约

(2)events 块:影响 Nginx 服务器与用户的网络连接
events 块涉及的指令主要影响 Nginx 服务器与用户的网络连接,常用的设置包括是否开启对多 work process
下的网络连接进行序列化,是否允许同时接收多个网络连接,选取哪种事件驱动模型来处理连接请求,每个 word
process 可以同时支持的最大连接数等。
上述例子就表示每个

最低0.47元/天 解锁文章
1297

被折叠的 条评论
为什么被折叠?



