Nginx优势及安装
Nginx优势及安装
为什么选择 nginx
1 | 1.高并发,高性能 |
yum安装
1.配置yum源安装nginx
1 | 清理原有数据 |
配置源码文件
1 | /etc/yum.repo.d/nginx.repo << EOF |
下载及启动服务
1 | yum -y install nginx |
2.yum源选择版本安装
1 | 配置Yum源的官网:http://nginx.org/en/linux_packages.html |
3.编译安装
关闭防火墙
1 | systemctl stop firewalld |
下载wget
1 | yum -y install wget |
安装编译环境
1 | yum -y install gcc gcc-c++ |
安装依赖pcre软件包(使nginx支持http rewrite模块)
1 | yum install -y pcre pcre-devel gd-devel |
安装依赖openssl-devel(使nginx支持ssl)
1 | yum install -y openssl openssl-devel |
安装依赖zlib
1 | yum install -y zlib zlib-devel |
创建nginx用户,不允许登录
1 | useradd nginx -s /sbin/nologin |
下载官方nginx
1 | wget https://nginx.org/download/nginx-1.24.0.tar.gz //下载1.24版本 |
解压nginx包
1 | tar zxvf nginx-1.24.0.tar.gz -C /usr/local/ |
切换目录
1 | cd /usr/local/nginx-1.24.0/ |
配置安装参数
1 | ./configure --prefix=/usr/local/nginx --group=nginx --user=nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/tmp/nginx/client_body --http-proxy-temp-path=/tmp/nginx/proxy --http-fastcgi-temp-path=/tmp/nginx/fastcgi --pid-path=/var/run/nginx.pid --lock-path=/var/lock/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-pcre --with-http_realip_module --with-stream |
过程当中如果出错,删除Makefile文件后重新配置
编译以及编译安装
1 | make && make install |
启动nginx服务
1 | /usr/local/nginx/sbin/nginx |
创建连接文件,可以直接用nginx命令
1 | ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx |
连接文件创建成功后,nginx常用命令
1 | nginx -s reload # 修改配置后重新加载生效 |
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来源 Dong_Blog!











