Nginx编译安装及平滑升级
2021/12/1 7:07:38
本文主要是介绍Nginx编译安装及平滑升级,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
基于仓库安装
官网地址: http://nginx.org/en/linux_packages.html
sudo apt install curl gnupg2 ca-certificates lsb-release ubuntu-keyring curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor | sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null gpg --dry-run --quiet --import --import-options import-show /usr/share/keyrings/nginx-archive-keyring.gpg echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \ http://nginx.org/packages/ubuntu `lsb_release -cs` nginx" | sudo tee /etc/apt/sources.list.d/nginx.list root@ops106:~# apt list nginx Listing... Done nginx/stable 1.20.2-1~focal arm64 N: There are 6 additional versions. Please use the '-a' switch to see them. root@ops106:~# apt install nginx # 查看版本及编译参数 root@ops106:~# nginx -V nginx version: nginx/1.20.2 built by gcc 9.3.0 (Ubuntu 9.3.0-10ubuntu2) built with OpenSSL 1.1.1f 31 Mar 2020 TLS SNI support enabled configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --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-compat --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 --with-cc-opt='-g -O2 -fdebug-prefix-map=/data/builder/debuild/nginx-1.20.2/debian/debuild-base/nginx-1.20.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -pie'
编译安装1.18.0
安装依赖工具
apt install gcc openssl libssl-dev libpcre3 libpcre3-dev zlib1g-dev make libncurses-dev libperl-d
创建用户
groupadd nginx useradd nginx -g nginx -s /sbin/nologin -M
下载软件包&解压
wget http://nginx.org/download/nginx-1.18.0.tar.gz tar xf nginx-1.18.0.tar.gz
修改相应报文Server首部(可选)
cd nginx-1.18.0 vim src/core/nginx.h #define NGINX_VERSION "1.11.30" #define NGINX_VER "super ops/" NGINX_VERSION # 没有禁用版本后显示 vim src/http/ngx_http_header_filter_module.c static u_char ngx_http_server_string[] = "Server: super ops" CRLF; # server_tokens off; 指令显示此处版本
编译安装
./configure --prefix=/usr/local/nginx \ --user=nginx \ --group=nginx \ --with-http_ssl_module \ --with-http_v2_module \ --with-http_realip_module \ --with-http_sub_module \ --with-http_stub_status_module \ --with-http_gzip_static_module \ --with-pcre \ --with-http_perl_module \ --with-stream \ --with-stream_ssl_module \ --with-stream_realip_module \ --with-http_addition_module \ --with-http_dav_module \ --with-http_flv_module \ --with-http_mp4_module make && make install
修改目录权限
chown -R nginx.nginx /usr/local/nginx
准备启动文件
cat /usr/lib/systemd/system/nginx.service [Unit] Description=nginx - high performance web server Documentation=https://nginx.org/en/docs/ After=network-online.target remote-fs.target nss-lookup.target Wants=network-online.target [Service] Type=forking PIDFile=/usr/local/nginx/run/nginx.pid ExecStart=/usr/local/bin/nginx -c /usr/local/nginx/conf/nginx.conf ExecReload=/bin/sh -c "/bin/kill -s HUP $(/bin/cat /usr/local/nginx/run/nginx.pid)" ExecStop=/bin/sh -c "/bin/kill -s TERM $(/bin/cat /usr/local/nginx/run/nginx.pid)" [Install] WantedBy=multi-user.target
启动测试
systemctl start nginx systemctl enable nginx systemctl status nginx
验证
curl -I 10.211.55.106 HTTP/1.1 200 OK Server: super ops/1.11.30 Date: Tue, 30 Nov 2021 12:21:57 GMT Content-Type: text/html Content-Length: 612 Last-Modified: Tue, 30 Nov 2021 12:11:57 GMT Connection: keep-alive ETag: "61a6150d-264" Accept-Ranges: bytes
这篇关于Nginx编译安装及平滑升级的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-10-29Nginx发布学习:从入门到实践的简单教程
- 2024-10-28Nginx发布:新手入门教程
- 2024-10-21nginx 怎么设置文件上传最大20M限制-icode9专业技术文章分享
- 2024-10-17关闭 nginx的命令是什么?-icode9专业技术文章分享
- 2024-09-17Nginx实用篇:实现负载均衡、限流与动静分离
- 2024-08-21宝塔nginx新增8022端口方法步骤-icode9专业技术文章分享
- 2024-08-21nginx配置,让ws升级为wss访问的方法步骤-icode9专业技术文章分享
- 2024-08-15nginx ws代理配置方法步骤-icode9专业技术文章分享
- 2024-08-14nginx 让访问带有/relid的地址返回404 ,例子 /relid-x-0.36-y-131.html-icode9专业技术文章分享
- 2024-08-14nginx 判断地址有/statics/的路径,指向到/home/html/statics/目录-icode9专业技术文章分享