debian编译安装nginx (202212)

参考原文:

1. 安装必要依存关系文件

sudo apt-get install curl build-essential make gcc libpcre3 libpcre3-dev libpcre++-dev zlib1g-dev libbz2-dev libxslt1-dev libxml2-dev libgeoip-dev libgoogle-perftools-dev libgd-dev libperl-dev libssl-dev libcurl4-openssl-dev

PCRE – Supports regular expressions. Required by the NGINX Core and Rewrite modules.

wget github.com/PCRE2Project/pcre2/releases/download/pcre2-10.40/pcre2-10.40.tar.gz
tar -zxf pcre2-10.40.tar.gz && cd pcre2-10.40 ./configure make sudo make install

zlib – Supports header compression. Required by the NGINX Gzip module.

cd ..
wget http://zlib.net/zlib-1.2.13.tar.gz tar -zxf zlib-1.2.13.tar.gz && cd zlib-1.2.13 ./configure make sudo make install
cd ..
sudo apt update

2. 下载并解压nginx

下载Mainline版

sudo wget http://nginx.org/download/nginx-1.23.3.tar.gz
sudo tar xvf nginx-1.23.3.tar.gz && cd nginx-1.23.3

3. 编译配置

sudo ./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           
--with-pcre=../pcre2-10.40                                 
--with-zlib=../zlib-1.2.13                                 
--with-http_ssl_module                                     
--with-http_realip_module                                  
--with-http_addition_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_random_index_module                            
--with-http_secure_link_module                             
--with-http_stub_status_module                             
--with-http_auth_request_module                            
--with-mail                                                
--with-mail_ssl_module                                     
--with-file-aio                                            
--with-http_v2_module                                      
--with-threads                                             
--with-stream                                              
--with-stream_ssl_module                                   
--with-stream_realip_module                                
--with-stream_ssl_preread_module                           
--with-http_slice_module

4. 安装

sudo make
sudo make install

5. 最后配置

  • 创建nginx用户
sudo useradd -r nginx

     查看已有用户以及用户组

cat  /etc/passwd
cat /etc/group
  • 创建nginx缓存文件夹
sudo mkdir /var/cache/nginx && sudo touch /var/cache/nginx/client_temp
  • 开机启动nginx
sudo nano /lib/systemd/system/nginx.service
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t
ExecStart=/usr/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target
  • sudo systemctl enable nginx
  •  常用命令
    • nginx -v
    • nginx -V
    • sudo pkill nginx
    • sudo systemctl start nginx
    • sudo systemctl status nginx
    • sudo systemctl enable nginx
    • systemctl is-enabled nginx.service
      (检查服务开机自动启动是否有效)

返信を残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です