CentOS 7 编译安装Nginx

来源:互联网 发布:dva的防御矩阵 编辑:程序博客网 时间:2024/05/24 23:11

一、准备工作:

1、安装必备工具:

$ yum -y install gcc gcc-c++ autoconf automake$ yum -y install zlib zlib-devel openssl openssl-devel pcre-devel
说明:

pcre: 用来作地址重写的功能。

zlib:nginx 的gzip模块,传输数据打包,省流量(但消耗资源)。

openssl:提供ssl加密协议。

2、安装之前,最好检查一下是否已经安装有nginx

$ find -name nginx 如果系统已经安装了nginx,那么就先卸载                                                                                                                      $ yum remove nginx  
如果系统已经安装了nginx,那么就先卸载                                                                                                                      

二、Nginx编译安装:

1、下载Nginx:http://nginx.org/en/download.html

$   cd /usr/local
$   wget http://nginx.org/download/nginx-1.13.0.tar.gz

2、解压编译:

$ tar -zxvf nginx-1.13.0.tar.gz$ cd nginx-1.13.0/$ ./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 \--user=nginx \--group=nginx \--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-ipv6 \--with-http_spdy_module \--with-cc-opt='-O2 -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic'

上面的参数的作用可以通过--help来查看下文附加1中有提供

$ ./configure --help
编译日志:
checking for OS + Linux 3.10.0-229.4.2.el7.x86_64 x86_64checking for C compiler ... found + using GNU C compiler + gcc version: 4.8.3 20140911 (Red Hat 4.8.3-9) (GCC) checking for gcc -pipe switch ... foundchecking for gcc builtin atomic operations ... foundchecking for C99 variadic macros ... foundchecking for gcc variadic macros ... foundchecking for unistd.h ... foundchecking for inttypes.h ... foundchecking for limits.h ... foundchecking for sys/filio.h ... not foundchecking for sys/param.h ... foundchecking for sys/mount.h ... foundchecking for sys/statvfs.h ... foundchecking for crypt.h ... foundchecking for Linux specific featureschecking for epoll ... foundchecking for EPOLLRDHUP ... foundchecking for O_PATH ... foundchecking for sendfile() ... foundchecking for sendfile64() ... foundchecking for sys/prctl.h ... foundchecking for prctl(PR_SET_DUMPABLE) ... foundchecking for sched_setaffinity() ... foundchecking for crypt_r() ... foundchecking for sys/vfs.h ... foundchecking for poll() ... foundchecking for /dev/poll ... not foundchecking for kqueue ... not foundchecking for crypt() ... not foundchecking for crypt() in libcrypt ... foundchecking for F_READAHEAD ... not foundchecking for posix_fadvise() ... foundchecking for O_DIRECT ... foundchecking for F_NOCACHE ... not foundchecking for directio() ... not foundchecking for statfs() ... foundchecking for statvfs() ... foundchecking for dlopen() ... not foundchecking for dlopen() in libdl ... foundchecking for sched_yield() ... foundchecking for SO_SETFIB ... not foundchecking for SO_REUSEPORT ... foundchecking for SO_ACCEPTFILTER ... not foundchecking for TCP_DEFER_ACCEPT ... foundchecking for TCP_KEEPIDLE ... foundchecking for TCP_FASTOPEN ... not foundchecking for TCP_INFO ... foundchecking for accept4() ... foundchecking for eventfd() ... foundchecking for int size ... 4 byteschecking for long size ... 8 byteschecking for long long size ... 8 byteschecking for void * size ... 8 byteschecking for uint64_t ... foundchecking for sig_atomic_t ... foundchecking for sig_atomic_t size ... 4 byteschecking for socklen_t ... foundchecking for in_addr_t ... foundchecking for in_port_t ... foundchecking for rlim_t ... foundchecking for uintptr_t ... uintptr_t foundchecking for system byte ordering ... little endianchecking for size_t size ... 8 byteschecking for off_t size ... 8 byteschecking for time_t size ... 8 byteschecking for setproctitle() ... not foundchecking for pread() ... foundchecking for pwrite() ... foundchecking for sys_nerr ... foundchecking for localtime_r() ... foundchecking for posix_memalign() ... foundchecking for memalign() ... foundchecking for mmap(MAP_ANON|MAP_SHARED) ... foundchecking for mmap("/dev/zero", MAP_SHARED) ... foundchecking for System V shared memory ... foundchecking for POSIX semaphores ... not foundchecking for POSIX semaphores in libpthread ... foundchecking for struct msghdr.msg_control ... foundchecking for ioctl(FIONBIO) ... foundchecking for struct tm.tm_gmtoff ... foundchecking for struct dirent.d_namlen ... not foundchecking for struct dirent.d_type ... foundchecking for sysconf(_SC_NPROCESSORS_ONLN) ... foundchecking for openat(), fstatat() ... foundchecking for getaddrinfo() ... foundchecking for PCRE library ... foundchecking for PCRE JIT support ... foundchecking for OpenSSL library ... foundchecking for zlib library ... foundcreating objs/MakefileConfiguration summary  + using system PCRE library  + using system OpenSSL library  + md5: using OpenSSL library  + sha1: using OpenSSL library  + using system zlib library  nginx path prefix: "/usr"  nginx binary file: "/usr/sbin/nginx"  nginx configuration prefix: "/etc/nginx"  nginx configuration file: "/etc/nginx/nginx.conf"  nginx pid file: "/var/run/nginx/nginx.pid"  nginx error log file: "/var/log/nginx/error.log"  nginx http access log file: "/var/log/nginx/http.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/fcgi"  nginx http uwsgi temporary files: "uwsgi_temp"  nginx http scgi temporary files: "scgi_temp"

好像很成功。

3、安装:

$ make && make install

4、启动:

$ /usr/local/nginx/sbin/nginx

5、其它:

停止:
$ /usr/local/nginx/sbin/nginx -s stop
查看版本及安装的模块(大写的V):
$ /usr/local/nginx/sbin/nginx -V



----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

原创粉丝点击