腾讯云的服务器快到期了,现在重新买了一台轻量云服务器,准备重新部署我的一些项目,一切都是新的,那就安装最新的系统,最新的软件进去!
# 安装必要的依赖和库
sudo dnf install -y pcre2 pcre2-devel libxml2 libxslt libxml2-devel libxslt-devel gd gd-devel geoip geoip-devel gperftools gperftools-devel |
# 创建 www 用户
useradd www |
# 下载 nginx , openssl
nginx
openssl
这里都选择目前的最新版本
下载之后放到一个文件夹里,然后分别解压
我选择 nginx-1.24.0
, openssl-3.2.0
# 进行编译安装
进入 nginx 目录下,执行下面的命令
./configure \ | |
--prefix=/usr/local/nginx \ | |
--user=www \ | |
--group=www \ | |
--with-pcre \ | |
--with-threads \ | |
--with-file-aio \ | |
--with-http_ssl_module \ | |
--with-http_v2_module \ | |
--with-http_realip_module \ | |
--with-http_addition_module \ | |
--with-http_xslt_module \ | |
--with-http_image_filter_module \ | |
--with-http_geoip_module \ | |
--with-http_sub_module \ | |
--with-http_dav_module \ | |
--with-http_flv_module \ | |
--with-http_mp4_module \ | |
--with-http_gunzip_module \ | |
--with-http_gzip_static_module \ | |
--with-http_auth_request_module \ | |
--with-http_random_index_module \ | |
--with-http_secure_link_module \ | |
--with-http_slice_module \ | |
--with-http_degradation_module \ | |
--with-http_stub_status_module \ | |
--with-http_perl_module \ | |
--with-mail \ | |
--with-stream \ | |
--with-stream_ssl_module \ | |
--with-stream_realip_module \ | |
--with-google_perftools_module \ | |
--with-openssl=/home/source/openssl-3.2.0 \ | |
--with-debug |
这里能装的扩展都装上,执行成功显示如下信息
Configuration summary | |
+ using threads | |
+ using system PCRE2 library | |
+ using OpenSSL library: /home/source/openssl-3.2.0 | |
+ 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" |
修改一下 Makefile 文件,将第二行的 CFLAGS 后面加 -fPIC
, 不然可能在编译的时候会报错退出
vim ./objs/Makefile | |
CFLAGS = -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -fPIC |
修改好之后保存退出
然后开始进行编译
make -j && make install |
耐心等待装完就 OK 了,大概 1-3 分钟
# 使用 systemd 管理 nginx
nginx 安装好之后,我们需要让它开机自启,在 linux 上使用 systemd 会非常简单
vim /etc/systemd/system/nginx.service |
将下面的代码粘贴进去,然后保存退出
[Unit] | |
Description=Nginx | |
After=network.target | |
[Service] | |
Type=forking | |
ExecStartPre=/usr/local/nginx/sbin/nginx -t -q -g 'daemon on; master_process on;' | |
ExecStart=/usr/local/nginx/sbin/nginx -g 'daemon on; master_process on;' | |
ExecReload=/usr/local/nginx/sbin/nginx -g 'daemon on; master_process on;' -s reload | |
ExecStop=/usr/local/nginx/sbin/nginx -g 'daemon on; master_process on;' -s quit | |
PrivateTmp=true | |
[Install] | |
WantedBy=multi-user.target |
执行 systemctl start nginx
启动一下
然后使用 systemctl status nginx
查看是否启动成功
使用 systemctl enable nginx
设为开机自启动
这样我们的 nginx 就装好了
# 结束
至此,nginx 安装完了