mac linux手动编译安装Nginx

前言

Nginx是一个性能非常不错的HTTP和反向代理服务器,目前已经成为很多Web项目部署的标配了。不过,由于很多Linux发行版包管理里面的源不是很新,所以诸如用yum或者apt安装的Nginx版本比较旧。因此,如果我们想用上最新版本的Nginx,需要我们手动从官方网站下载最新源码来进行编译安装。这里小记一下手动编译安装Nginx的过程,作为备忘,方便以后查阅。

准备过程

均下载tar.gz源码

  1. 下载PCRE库,并解压 。http://www.pcre.org/
  2. 下载zlib库,并解压 http://www.zlib.net/
  3. 下载Nginx的最新代码,解压

编译安装过程

cd到nginx源码路径

  • 写好各种参数,到Nginx的源码目录下运行配置命令。其中,还要使用参数指向刚才下载的PCRE和zlib库的位置:
  • ./configure --prefix=/usr/local/nginx --pid-path=/var/run/nginx.pid --lock-path=/var/lock/nginx.lock --with-http_ssl_module --with-http_dav_module --with-http_flv_module --with-http_realip_module --with-http_gzip_static_module --with-http_stub_status_module --with-mail --with-mail_ssl_module --with-pcre=../pcre-8.37 --with-zlib=../zlib-1.2.8 --with-debug --http-client-body-temp-path=/var/tmp/nginx/client --http-proxy-temp-path=/var/tmp/nginx/proxy --http-fastcgi-temp-path=/var/tmp/nginx/fastcgi --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi
    • 这三个库考虑用绝对路径  
    • + using PCRE library: /Users/zlb/application/pcre-8.37
        + using OpenSSL library: /Users/zlb/application/openssl-1.1.0h
        + using zlib library: /Users/zlb/application/zlib-1.2.11

    • 编译并安装
    • make && make install

    等待一些时间,就编译安装成功了

附录

附上一些常用配置参数的含义:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
--prefix #nginx安装目录,默认在/usr/local/nginx
--pid-path #pid问件位置,默认在logs目录
--lock-path #lock问件位置,默认在logs目录
--with-http_ssl_module #开启HTTP SSL模块,以支持HTTPS请求。
--with-http_dav_module #开启WebDAV扩展动作模块,可为文件和目录指定权限
--with-http_flv_module #支持对FLV文件的拖动播放
--with-http_realip_module #支持显示真实来源IP地址
--with-http_gzip_static_module #预压缩文件传前检查,防止文件被重复压缩
--with-http_stub_status_module #取得一些nginx的运行状态
--with-mail #允许POP3/IMAP4/SMTP代理模块
--with-mail_ssl_module #允许POP3/IMAP/SMTP可以使用SSL/TLS
--with-pcre=../pcre-8.11 #注意是未安装的pcre路径
--with-zlib=../zlib-1.2.5 #注意是未安装的zlib路径
--with-debug #允许调试日志
--http-client-body-temp-path #客户端请求临时文件路径
--http-proxy-temp-path #设置http proxy临时文件路径
--http-fastcgi-temp-path #设置http fastcgi临时文件路径
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi #设置uwsgi 临时文件路径
--http-scgi-temp-path=/var/tmp/nginx/scgi #设置scgi 临时文件路径



日志:



zhenglubiaodeMacBook-Pro:nginx-1.13.12 zlb$ ./configure --prefix=/usr/local/nginx --pid-path=/var/run/nginx.pid --lock-path=/var/lock/nginx.lock --with-http_ssl_module --with-http_dav_module --with-http_flv_module --with-http_realip_module --with-http_gzip_static_module --with-http_stub_status_module --with-mail --with-mail_ssl_module --with-pcre=/Users/zlb/application/pcre-8.37  --with-zlib=/Users/zlb/application/zlib-1.2.11 --with-debug --http-client-body-temp-path=/var/tmp/nginx/client --http-proxy-temp-path=/var/tmp/nginx/proxy --http-fastcgi-temp-path=/var/tmp/nginx/fastcgi --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi --with-openssl=/Users/zlb/application/openssl-1.1.0h 
checking for OS
 + Darwin 17.3.0 x86_64
checking for C compiler ... found
 + using Clang C compiler
 + clang version: 9.1.0 (clang-902.0.39.1)
checking for -Wl,-E switch ... not 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 ... found
checking for sys/param.h ... found
checking for sys/mount.h ... found
checking for sys/statvfs.h ... found
checking for crypt.h ... not found
checking for Darwin specific features
 + kqueue found
checking for kqueue's EVFILT_TIMER ... found
checking for Darwin 64-bit kqueue millisecond timeout bug ... not found
checking for sendfile() ... found
checking for atomic(3) ... found
checking for nobody group ... found
checking for poll() ... found
checking for /dev/poll ... not found
checking for crypt() ... found
checking for F_READAHEAD ... not found
checking for posix_fadvise() ... not found
checking for O_DIRECT ... not found
checking for F_NOCACHE ... found
checking for directio() ... not found
checking for statfs() ... found
checking for statvfs() ... found
checking for dlopen() ... found
checking for sched_yield() ... found
checking for sched_setaffinity() ... not 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 ... not found
checking for IP_BINDANY ... not found
checking for IP_BIND_ADDRESS_NO_PORT ... not found
checking for IP_RECVDSTADDR ... found
checking for IP_SENDSRCADDR ... not found
checking for IP_PKTINFO ... found
checking for IPV6_RECVPKTINFO ... found
checking for TCP_DEFER_ACCEPT ... not found
checking for TCP_KEEPIDLE ... not found
checking for TCP_FASTOPEN ... found
checking for TCP_INFO ... not found
checking for accept4() ... not found
checking for eventfd() ... not found
checking for eventfd() (SYS_eventfd) ... not 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() ... 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() ... not found
checking for mmap(MAP_ANON|MAP_SHARED) ... found
checking for mmap("/dev/zero", MAP_SHARED) ... found but is not working
checking for System V shared memory ... found
checking for POSIX semaphores ... found but is not working
checking for POSIX semaphores in libpthread ... found but is not working
checking for POSIX semaphores in librt ... not found
checking for struct msghdr.msg_control ... found
checking for ioctl(FIONBIO) ... found
checking for struct tm.tm_gmtoff ... found
checking for struct dirent.d_namlen ... found
checking for struct dirent.d_type ... found
checking for sysconf(_SC_NPROCESSORS_ONLN) ... found
checking for sysconf(_SC_LEVEL1_DCACHE_LINESIZE) ... not found
checking for openat(), fstatat() ... found
checking for getaddrinfo() ... found
creating objs/Makefile


Configuration summary
  + using PCRE library: /Users/zlb/application/pcre-8.37
  + using OpenSSL library: /Users/zlb/application/openssl-1.1.0h
  + using zlib library: /Users/zlb/application/zlib-1.2.11


  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: "/var/run/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: "/var/tmp/nginx/client"
  nginx http proxy temporary files: "/var/tmp/nginx/proxy"
  nginx http fastcgi temporary files: "/var/tmp/nginx/fastcgi"
  nginx http uwsgi temporary files: "/var/tmp/nginx/uwsgi"
  nginx http scgi temporary files: "/var/tmp/nginx/scgi"


zhenglubiaodeMacBook-Pro:nginx-1.13.12 zlb$ 








猜你喜欢

转载自blog.csdn.net/qq_34294513/article/details/80064238