提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
名称 | 使用场景 |
---|---|
docker | 容器化 可以看作一个小的应用服务器 |
kvm | 虚拟化 (没有办法完全利用主机资源【cpu 内存 磁盘 ,网络带宽】) |
主机 | 需要提升一个nginx 的性能的时候,响应一个极高的访问量 |
(1) 下载地址:Nginx官网
(2) 将下载的nginx安装包nginx-1.20.2.tar.zip 通过ftp工具上传到linux主机上并解压nginx安装包
[root@bogon local]# chmod -R 777 nginx-1.20.2.tar.gz
[root@bogon local]# tar -zxvf nginx-1.20.2.tar.gz
编译nginx
[root@bogon nginx-1.20.2]# ./configure --prefix=/usr/local/nginx
注意⚠️:编辑过程中可能会出现的错误:
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.
安装perl库
yum install -y pcre pcre-devel
./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using --without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using --with-zlib=<path> option.
安装zlib
[root@bogon nginx-1.20.2]# yum install -y zlib zlib-devel
[root@bogon nginx-1.20.2]# yum install gcc
使用yum命令安装openssl
[root@bogon sbin]# yum install openssl-devel
编译完成后可以看到
Configuration summary
+ using system PCRE library
+ OpenSSL library is not used
+ using system zlib library
nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/sbin/nginx"
nginx modules path: "/usr/local/nginx/modules"
nginx configuration prefix: "/usr/local/nginx/conf"
nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
nginx pid file: "/usr/local/nginx/logs/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
nginx http access log file: "/usr/local/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"
(4)编译完成后执行make命令
make
完成后可以看到
objs/ngx_modules.o \
-ldl -lpthread -lcrypt -lpcre -lz \
-Wl,-E
sed -e "s|%%PREFIX%%|/usr/local/nginx|" \
-e "s|%%PID_PATH%%|/usr/local/nginx/logs/nginx.pid|" \
-e "s|%%CONF_PATH%%|/usr/local/nginx/conf/nginx.conf|" \
-e "s|%%ERROR_LOG_PATH%%|/usr/local/nginx/logs/error.log|" \
< man/nginx.8 > objs/nginx.8
make[1]: 离开目录“/usr/local/nginx-1.20.2”
(5)执行make install命令
[root@bogon nginx-1.20.2]# make install
[root@bogon sbin]# ./nginx
看到 Welcome to nginx! 就是启动完成,如果不是本机访问的话,可能是防火墙的限制
[root@bogon sbin]# vi /usr/lib/systemd/system/nginx.service
脚本内容:
# 服务的说明
[Unit]
# 描述服务
Description=nginx
# 描述服务类别
After=network.target remote-fs.target nss-lookup.target
# 服务运行参数的设置
[Service]
# 后台运行的形式
Type=forking
# 启动命令
ExecStart=/usr/local/nginx/sbin/nginx
# 重启命令
ExecReload=/usr/local/nginx/sbin/nginx -s reload
# 停止命令
ExecStop=/usr/local/nginx/sbin/nginx -s stop
# 服务安装的设置
[Install]
# 用户的模式
WantedBy=multi-user.target
重新加载系统服务
[root@bogon sbin]# systemctl daemon-reload
启动命令
systemctl start nginx.service
停止命令
systemctl stop nginx.service
查看nginx状态命令
systemctl status nginx.service