文档
Nginx 安装
# 配置
./configure --with-http_ssl_module --with-http_v2_module
# 安装
make && make install
# 安装:多线程编译
make -j 4 && make install
# 根据 CPU 核心数进行多线程编译
# make -j $(grep 'processor' /proc/cpuinfo | wc -l) && make install
# 安装结果
......
Configuration summary
+ using system PCRE2 library
+ using system OpenSSL library
+ 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"
# 查看版本
/usr/local/nginx/sbin/nginx -V
# 版本示例
root@xxw-1:/srv/nginx-1.29.2# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.29.2
built by gcc 14.2.0 (Debian 14.2.0-19)
built with OpenSSL 3.5.1 1 Jul 2025
TLS SNI support enabled
configure arguments: --with-http_ssl_module --with-http_v2_module
root@xxw-1:/srv/nginx-1.29.2#
# 软链接
ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx
nginx -V
# 测试配置
nginx -t
# 重新加载配置
nginx -s reload
Nginx Linux 服务内容
# 安装服务
cat << EOF > /lib/systemd/system/nginx.service
[Unit]
Description=nginx
After=network.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
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOF
# 服务命令
# 查看服务状态
systemctl status nginx.service
# 启动服务
systemctl start nginx.service
# 重启服务
systemctl restart nginx.service
# 停止服务
systemctl stop nginx.service
# 打开开机自启
systemctl enable nginx.service
# 关闭开机自启
systemctl disable nginx.service
# 查看是否开机自启
systemctl is-enabled nginx.service
Nginx 安装问题
–with-pcre/–without-http_rewrite_module
./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.
# apt
sudo apt update
sudo apt -y install libpcre2-dev
# yum
yum -y install pcre-devel
–with-zlib/–without-http_gzip_module
./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.
# apt
sudo apt update
sudo apt -y install zlib1g-dev
# yum
yum -y install zlib-devel
–with-openssl/–with-http_ssl_module
./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl=<path> option.
# apt
sudo apt update
sudo apt -y install libssl-dev
# yum
yum -y install openssl-devel
Nginx 不返回版本号
http {
# 其他配置项
server_tokens off;
# 其他配置项
}