Nginx安装与启动

工具条件

  • VMware Workstation Pro
  • CentOS 7 64位
  • nginx-1.21.6

官网下载地址:nginx: download

Nignx的安装主要分为三步走:配置(configure)编译(make)安装(make install)

配置安装

切换根root用户

[ltao@localhost nginx-1.21.6]$ su root
Password: 

创建目录 user/src 将Nginx压缩包放入 src 文件夹下。解压 nginx-1.21.6.tar.gz

[ltao@localhost src]$ ls
nginx-1.21.6.tar.gz
[ltao@localhost src]$ tar -xf nginx-1.21.6.tar.gz 
[ltao@localhost src]$ ls
nginx-1.21.6  nginx-1.21.6.tar.gz

需要安装的依赖:gcc 、pcre-devel(URL重写功能)和 zlib 库(解压缩)

[root@localhost nginx-1.21.6]# yum -y install gcc pcre-devel zlib zlib-devel

配置安装的路径。

[root@localhost nginx-1.21.6]# ./configure --prefix=/user/local/nginx
checking for OS
 + Linux 3.10.0-1160.el7.x86_64 x86_64
checking for C compiler ... found
 + using GNU C compiler
 + gcc version: 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) 
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 ... not 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 nobody 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 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 zlib library ... found
creating objs/Makefile

Configuration summary
  + using system PCRE library
  + OpenSSL library is not used
  + using system zlib library

  nginx path prefix: "/user/local/nginx"
  nginx binary file: "/user/local/nginx/sbin/nginx"
  nginx modules path: "/user/local/nginx/modules"
  nginx configuration prefix: "/user/local/nginx/conf"
  nginx configuration file: "/user/local/nginx/conf/nginx.conf"
  nginx pid file: "/user/local/nginx/logs/nginx.pid"
  nginx error log file: "/user/local/nginx/logs/error.log"
  nginx http access log file: "/user/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"

检查日志信息没有出现 error 信息就安装完成了。如有出现 error 需要解决后再次执行安装命令。

执行make;make的作用就是将源码编译生成可执行程序的过程。

[root@localhost nginx-1.21.6]#  make
make -f objs/Makefile
make[1]: Entering directory `/home/ltao/user/src/nginx-1.21.6'
# ......
# 日志信息
# ......
-ldl -lpthread -lcrypt -lpcre -lz \
-Wl,-E
sed -e "s|%%PREFIX%%|/user/local/nginx|" \
	-e "s|%%PID_PATH%%|/user/local/nginx/logs/nginx.pid|" \
	-e "s|%%CONF_PATH%%|/user/local/nginx/conf/nginx.conf|" \
	-e "s|%%ERROR_LOG_PATH%%|/user/local/nginx/logs/error.log|" \
	< man/nginx.8 > objs/nginx.8
make[1]: Leaving directory `/home/ltao/user/src/nginx-1.21.6'

安装make生成的可执行程序

[root@localhost nginx-1.21.6]# make install
make -f objs/Makefile install
make[1]: Entering directory `/home/ltao/user/src/nginx-1.21.6'
test -d '/user/local/nginx' || mkdir -p '/user/local/nginx'
test -d '/user/local/nginx/sbin' \
	|| mkdir -p '/user/local/nginx/sbin'
test ! -f '/user/local/nginx/sbin/nginx' \
	|| mv '/user/local/nginx/sbin/nginx' \
		'/user/local/nginx/sbin/nginx.old'
cp objs/nginx '/user/local/nginx/sbin/nginx'
test -d '/user/local/nginx/conf' \
	|| mkdir -p '/user/local/nginx/conf'
cp conf/koi-win '/user/local/nginx/conf'
cp conf/koi-utf '/user/local/nginx/conf'
cp conf/win-utf '/user/local/nginx/conf'
test -f '/user/local/nginx/conf/mime.types' \
	|| cp conf/mime.types '/user/local/nginx/conf'
cp conf/mime.types '/user/local/nginx/conf/mime.types.default'
test -f '/user/local/nginx/conf/fastcgi_params' \
	|| cp conf/fastcgi_params '/user/local/nginx/conf'
cp conf/fastcgi_params \
	'/user/local/nginx/conf/fastcgi_params.default'
test -f '/user/local/nginx/conf/fastcgi.conf' \
	|| cp conf/fastcgi.conf '/user/local/nginx/conf'
cp conf/fastcgi.conf '/user/local/nginx/conf/fastcgi.conf.default'
test -f '/user/local/nginx/conf/uwsgi_params' \
	|| cp conf/uwsgi_params '/user/local/nginx/conf'
cp conf/uwsgi_params \
	'/user/local/nginx/conf/uwsgi_params.default'
test -f '/user/local/nginx/conf/scgi_params' \
	|| cp conf/scgi_params '/user/local/nginx/conf'
cp conf/scgi_params \
	'/user/local/nginx/conf/scgi_params.default'
test -f '/user/local/nginx/conf/nginx.conf' \
	|| cp conf/nginx.conf '/user/local/nginx/conf/nginx.conf'
cp conf/nginx.conf '/user/local/nginx/conf/nginx.conf.default'
test -d '/user/local/nginx/logs' \
	|| mkdir -p '/user/local/nginx/logs'
test -d '/user/local/nginx/logs' \
	|| mkdir -p '/user/local/nginx/logs'
test -d '/user/local/nginx/html' \
	|| cp -R html '/user/local/nginx'
test -d '/user/local/nginx/logs' \
	|| mkdir -p '/user/local/nginx/logs'
make[1]: Leaving directory `/home/ltao/user/src/nginx-1.21.6'

安装完成。查看目录情况

[root@localhost nginx]# ls
conf  html  logs  sbin

启动

Nginx 默认占用 80 端口。启动前查看端口是否占用。俩种方式:

# lsof 命令
[root@localhost nginx]# lsof -i :80
# netstat 
[root@localhost nginx]# netstat -ntpl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 192.168.122.1:53        0.0.0.0:*               LISTEN      1666/dnsmasq        
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1122/sshd           
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      1128/cupsd          
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1709/master         
tcp        0      0 127.0.0.1:6010          0.0.0.0:*               LISTEN      10144/sshd: ltao@pt 
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      607/rpcbind         
tcp6       0      0 :::22                   :::*                    LISTEN      1122/sshd           
tcp6       0      0 ::1:631                 :::*                    LISTEN      1128/cupsd          
tcp6       0      0 ::1:25                  :::*                    LISTEN      1709/master         
tcp6       0      0 ::1:6010                :::*                    LISTEN      10144/sshd: ltao@pt 
tcp6       0      0 :::111                  :::*                    LISTEN      607/rpcbind  

# 启动命令
[root@localhost nginx]# /user/local/nginx/sbin/nginx
[root@localhost nginx]# 
# 查看是否启动
[root@localhost nginx]# lsof -i :80
COMMAND   PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
nginx   66187   root    6u  IPv4 139637      0t0  TCP *:http (LISTEN)
nginx   66188 nobody    6u  IPv4 139637      0t0  TCP *:http (LISTEN)

使用文本浏览器访问测试。如没有 elinks 文件浏览器。则使用 yum 命令安装。

[root@localhost nginx]# elinks http://192.168.255.128 --dump
bash: elinks: command not found...
[root@localhost nginx]# yum -y install elinks
[root@localhost nginx]#
[root@localhost nginx]# elinks http://192.168.255.128 --dump
                               Welcome to nginx!

   If you see this page, the nginx web server is successfully installed and
   working. Further configuration is required.

   For online documentation and support please refer to [1]nginx.org.
   Commercial support is available at [2]nginx.com.

   Thank you for using nginx.

References

   Visible links
   1. http://nginx.org/
   2. http://nginx.com/
[root@localhost nginx]# 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值