Ubuntu 20.04 安装Nginx-1.25.4

发布于:2024-04-20 ⋅ 阅读:(20) ⋅ 点赞:(0)

 

操作系统:Ubuntu 20.04.5 LTS

软件版本:nginx-1.25.4

 

一、环境准备

安装GCC编译器

安装PCRE

安装OpenSSL

安装OpenSSL库
安装zlib库

# 安装GCC编译器(build-essential 包会安装GCC编译器以及其他一些用于编译源代码的必须工具)

sudo apt update && sudo apt install build-essential

# 安装PCRE

sudo apt update && sudo apt install libpcre3 libpcre3-dev

# 安装OpenSSL

sudo apt update && sudo apt install openssl

# 安装OpenSSL库

sudo apt update && sudo apt install libssl-dev

# 安装zlib库

sudo apt install zlib1g-dev

二、安装Nginx

 

# 下载最新的nginx

wget https://nginx.org/download/nginx-1.25.4.tar.gz


# 解压

tar zxvf nginx-1.25.4.tar.gz

# 打开目录

cd nginx-1.25.4


# 配置

./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_sub_module --with-http_ssl_module

 下面是configure运行后正常的结果

root@master:/install/nginx-1.25.4# 
root@master:/install/nginx-1.25.4# ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_sub_module --with-http_ssl_module
checking for OS
 + Linux 5.4.0-176-generic x86_64
checking for C compiler ... found
 + using GNU C compiler
 + gcc version: 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04.2) 
checking for gcc -pipe switch ... found
checking for -Wl,-E switch ... found
checking for gcc builtin atomic operations ... found
checking for C99 variadic macros ... found
checking for gcc variadic macros ... found
checking for gcc builtin 64 bit byteswap ... found
checking for unistd.h ... found
checking for inttypes.h ... found
checking for limits.h ... found
checking for sys/filio.h ... not found
checking for sys/param.h ... found
checking for sys/mount.h ... found
checking for sys/statvfs.h ... found
checking for crypt.h ... found
checking for Linux specific features
checking for epoll ... found
checking for EPOLLRDHUP ... found
checking for EPOLLEXCLUSIVE ... found
checking for eventfd() ... found
checking for O_PATH ... found
checking for sendfile() ... found
checking for sendfile64() ... found
checking for sys/prctl.h ... found
checking for prctl(PR_SET_DUMPABLE) ... found
checking for prctl(PR_SET_KEEPCAPS) ... found
checking for capabilities ... found
checking for crypt_r() ... found
checking for sys/vfs.h ... found
checking for BPF sockhash ... found
checking for SO_COOKIE ... found
checking for UDP_SEGMENT ... found
checking for nobody group ... not found
checking for nogroup group ... found
checking for poll() ... found
checking for /dev/poll ... not found
checking for kqueue ... not found
checking for crypt() ... not found
checking for crypt() in libcrypt ... found
checking for F_READAHEAD ... not found
checking for posix_fadvise() ... found
checking for O_DIRECT ... found
checking for F_NOCACHE ... not found
checking for directio() ... not found
checking for statfs() ... found
checking for statvfs() ... found
checking for dlopen() ... not found
checking for dlopen() in libdl ... found
checking for sched_yield() ... found
checking for sched_setaffinity() ... found
checking for SO_SETFIB ... not found
checking for SO_REUSEPORT ... found
checking for SO_ACCEPTFILTER ... not found
checking for SO_BINDANY ... not found
checking for IP_TRANSPARENT ... found
checking for IP_BINDANY ... not found
checking for IP_BIND_ADDRESS_NO_PORT ... found
checking for IP_RECVDSTADDR ... not found
checking for IP_SENDSRCADDR ... not found
checking for IP_PKTINFO ... found
checking for IPV6_RECVPKTINFO ... found
checking for IP_MTU_DISCOVER ... found
checking for IPV6_MTU_DISCOVER ... found
checking for IP_DONTFRAG ... not found
checking for IPV6_DONTFRAG ... found
checking for TCP_DEFER_ACCEPT ... found
checking for TCP_KEEPIDLE ... found
checking for TCP_FASTOPEN ... found
checking for TCP_INFO ... found
checking for accept4() ... found
checking for int size ... 4 bytes
checking for long size ... 8 bytes
checking for long long size ... 8 bytes
checking for void * size ... 8 bytes
checking for uint32_t ... found
checking for uint64_t ... found
checking for sig_atomic_t ... found
checking for sig_atomic_t size ... 4 bytes
checking for socklen_t ... found
checking for in_addr_t ... found
checking for in_port_t ... found
checking for rlim_t ... found
checking for uintptr_t ... uintptr_t found
checking for system byte ordering ... little endian
checking for size_t size ... 8 bytes
checking for off_t size ... 8 bytes
checking for time_t size ... 8 bytes
checking for AF_INET6 ... found
checking for setproctitle() ... not found
checking for pread() ... found
checking for pwrite() ... found
checking for pwritev() ... found
checking for strerrordesc_np() ... not found
checking for sys_nerr ... found
checking for localtime_r() ... found
checking for clock_gettime(CLOCK_MONOTONIC) ... found
checking for posix_memalign() ... found
checking for memalign() ... found
checking for mmap(MAP_ANON|MAP_SHARED) ... found
checking for mmap("/dev/zero", MAP_SHARED) ... found
checking for System V shared memory ... found
checking for POSIX semaphores ... not found
checking for POSIX semaphores in libpthread ... found
checking for struct msghdr.msg_control ... found
checking for ioctl(FIONBIO) ... found
checking for ioctl(FIONREAD) ... found
checking for struct tm.tm_gmtoff ... found
checking for struct dirent.d_namlen ... not found
checking for struct dirent.d_type ... found
checking for sysconf(_SC_NPROCESSORS_ONLN) ... found
checking for sysconf(_SC_LEVEL1_DCACHE_LINESIZE) ... found
checking for openat(), fstatat() ... found
checking for getaddrinfo() ... found
checking for PCRE2 library ... not found
checking for PCRE library ... found
checking for PCRE JIT support ... found
checking for OpenSSL library ... found
checking for zlib library ... found
creating objs/Makefile

Configuration summary
  + using system PCRE 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"

root@master:/install/nginx-1.25.4# 

编译安装

make & make install

启动nginx(临时)

/usr/local/nginx/sbin/nginx

查看nginx进程

ps -ef|grep nginx

查看nginx版本和已安装的模块

/usr/local/nginx/sbin/nginx -V

创建服务文件
 

vim /usr/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 quit
PrivateTmp=true
 
[Install]
WantedBy=multi-user.target

 添加权限

chmod +x /usr/lib/systemd/system/nginx.service

设置开机自启

systemctl daemon-reload && systemctl enable tomcat.service

启动nginx

systemctl start nginx

查看nginx状态

root@master:/# systemctl status nginx
● nginx.service - nginx
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2024-04-15 08:04:11 UTC; 1min 31s ago
    Process: 25573 ExecStart=/usr/local/nginx/sbin/nginx (code=exited, status=0/SUCCESS)
   Main PID: 25574 (nginx)
      Tasks: 2 (limit: 9426)
     Memory: 1.9M
     CGroup: /system.slice/nginx.service
             ├─25574 nginx: master process /usr/local/nginx/sbin/nginx
             └─25575 nginx: worker process

Apr 15 08:04:11 cngscccw-vpa758 systemd[1]: Starting nginx...
Apr 15 08:04:11 cngscccw-vpa758 systemd[1]: Started nginx.
root@master:/#

三、安装命令一条龙

附上所有的命令清单和步骤

# 安装GCC编译器(build-essential 包会安装GCC编译器以及其他一些用于编译源代码的必须工具)

sudo apt update && sudo apt install build-essential

# 安装PCRE

sudo apt update && sudo apt install libpcre3 libpcre3-dev

# 安装OpenSSL

sudo apt update && sudo apt install openssl

# 安装OpenSSL库

sudo apt update && sudo apt install libssl-dev

# 安装zlib库

sudo apt install zlib1g-dev

# 下载最新的nginx

wget https://nginx.org/download/nginx-1.25.4.tar.gz


# 解压

tar zxvf nginx-1.25.4.tar.gz


# 配置

./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_sub_module --with-http_ssl_module

# 编译和安装

make & make install

# 启动nginx(临时)

/usr/local/nginx/sbin/nginx

# 查看nginx进程

ps -ef|grep nginx

# 查看nginx版本和已安装的模块

/usr/local/nginx/sbin/nginx -V

# 创建服务文件

vim /usr/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 quit
PrivateTmp=true
 
[Install]
WantedBy=multi-user.target

# 添加权限

chmod +x /usr/lib/systemd/system/nginx.service

# 设置开机自启

systemctl daemon-reload && systemctl enable tomcat.service

# 启动nginx

systemctl start nginx




 


 

 

 

 


网站公告

今日签到

点亮在社区的每一天
去签到