1.去官网下载文件
nginx官网
2.解决nginx安装中的各种依赖
- GCC编译器:
yum install gcc gcc-c++
- 正则表达式PCRE库:
yum install -y pcre pcre-devel
- zlib压缩库:
yum install -y zlib zlib-devel
- OpenSSL开发库:
yum install -y openssl openssl-devel
3.安装目录及参数规划
- nginx安装目录:
/etc/nginx
- nginx配置文件目录:
/usr/local/nginx/nginx.conf
- nginx虚拟服务器配置目录:
/usr/local/nginx/vhost/
- log日志目录:
/var/log/nginx/
- pid文件目录:
/var/run/nginx.pid
- lock锁目录:
/var/run/nginx.lock
- 临时缓存目录:
/var/cache/nginx
- 站点目录:
/www/wwwroot/
- nginx运行用户名:
nginx
- nginx运行用户组:
nginx
4 configure的命令参数
- 列出configure包含的参数:
./configure --help
5 Nginx编译步骤
- 创建nginx用户及用户组
- groupaddd nginx
- useradd -g nginx nginx
- 把准备好的nginx源码包解压
- mkdir /opt/nginx
- tar -xvf nginx-1.20.2.tar.gz -C /opt/nginx
- 进入到nginx的目录当中
- cd /opt/nginx
- 生成Makefile 文件
-
./configure \ --prefix=/etc/nginx \ --sbin-path=/usr/sbin/nginx \ --conf-path=/etc/nginx/nginx.conf \ --error-log-path=/var/log/nginx/error.log \ --http-log-path=/var/log/nginx/access.log \ --pid-path=/var/run/nginx.pid \ --lock-path=/var/run/nginx.lock \ --http-client-body-temp-path=/var/cache/nginx/client_temp \ --http-proxy-temp-path=/var/cache/nginx/proxy_temp \ --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \ --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \ --http-scgi-temp-path=/var/cache/nginx/scgi_temp \ --user=nginx \ --group=nginx \ --with-file-aio \ --with-threads \ --with-http_addition_module \ --with-http_auth_request_module \ --with-http_dav_module \ --with-http_flv_module \ --with-http_gunzip_module \ --with-http_gzip_static_module \ --with-http_mp4_module \ --with-http_random_index_module \ --with-http_realip_module \ --with-http_secure_link_module \ --with-http_slice_module \ --with-http_ssl_module \ --with-http_stub_status_module \ --with-http_sub_module \ --with-http_v2_module \ --with-mail \ --with-mail_ssl_module \ --with-stream \ --with-stream_realip_module \ --with-stream_ssl_module \ --with-stream_ssl_preread_module
- 编译与安装
- make && make install
-
安装成功执行以下命令查看nginx版本号
- nginx -v
- 查找nginx的文件
- whereis nginx
- nginx: /usr/sbin/nginx /etc/nginx
- 启动nginx服务
- cd /usr/sbin/
- ./nginx
- 查看服务
- ps -aux | grep nginx | grep -v grep
-
nginx 安装过程中出现的问题
- mkdir: 无法创建目录"/var/cache/nginx/client_temp":
- mkdir -p /var/cache/nginx/client_temp
- nginx: [emerg] getpwnam("nginx") failed
- useradd -s /sbin/nologin -M nginx