一、安装pcre
查看是否已经安装了pcre
rpm -qa | grep pcre
如果存在,则删除已经安装的pcre(最好不要用系统自带的pcre)
rpm -e --nodeps pcre-7.8-6.el6.x86_64
安装pcre
yum install pcre*
二、安装openssl
yum -y install openssl*
三、下载Nginx编译安装包
下载地址:http://Nginx.org/en/download.html
下载完成后解压在服务器的某个目录;
然后进度Nginx的解压目录:
cd /home/software/Nginx-1.11.5
执行安装前的配置检查(增加prefix参数,是为了提供Nginx的安装目录)
./configure --prefix=/home/Nginx-1.11.5 --with-http_ssl_module --with-http_v2_module --with-http_stub_status_module --with-pcre执行结束,如果没有发现error信息,则可以看到系统打印出:
...... 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 sys_nerr ... found checking for localtime_r() ... 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 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 openat(),fstatat() ... found checking for getaddrinfo() ... found checking for PCRE library ... found checking for PCRE JIT support ... not 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: "/home/Nginx-1.11.5" Nginx binary file: "/home/Nginx-1.11.5/sbin/Nginx" Nginx modules path: "/home/Nginx-1.11.5/modules" Nginx configuration prefix: "/home/Nginx-1.11.5/conf" Nginx configuration file: "/home/Nginx-1.11.5/conf/Nginx.conf" Nginx pid file: "/home/Nginx-1.11.5/logs/Nginx.pid" Nginx error log file: "/home/Nginx-1.11.5/logs/error.log" Nginx http access log file: "/home/Nginx-1.11.5/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"
然后进行编译,当前目录执行make命令
make
编译结束后,如果没有错误,则正常结束,如下图
...... objs/src/http/ngx_http_write_filter_module.o \ objs/src/http/ngx_http_header_filter_module.o \ objs/src/http/modules/ngx_http_chunked_filter_module.o \ objs/src/http/v2/ngx_http_v2_filter_module.o \ objs/src/http/modules/ngx_http_range_filter_module.o \ objs/src/http/modules/ngx_http_gzip_filter_module.o \ objs/src/http/ngx_http_postpone_filter_module.o \ objs/src/http/modules/ngx_http_ssi_filter_module.o \ objs/src/http/modules/ngx_http_charset_filter_module.o \ objs/src/http/modules/ngx_http_userid_filter_module.o \ objs/src/http/modules/ngx_http_headers_filter_module.o \ objs/src/http/ngx_http_copy_filter_module.o \ objs/src/http/modules/ngx_http_not_modified_filter_module.o \ objs/src/http/v2/ngx_http_v2.o \ objs/src/http/v2/ngx_http_v2_table.o \ objs/src/http/v2/ngx_http_v2_huff_decode.o \ objs/src/http/v2/ngx_http_v2_huff_encode.o \ objs/src/http/v2/ngx_http_v2_module.o \ objs/src/http/modules/ngx_http_static_module.o \ objs/src/http/modules/ngx_http_autoindex_module.o \ objs/src/http/modules/ngx_http_index_module.o \ objs/src/http/modules/ngx_http_auth_basic_module.o \ objs/src/http/modules/ngx_http_access_module.o \ objs/src/http/modules/ngx_http_limit_conn_module.o \ objs/src/http/modules/ngx_http_limit_req_module.o \ objs/src/http/modules/ngx_http_geo_module.o \ objs/src/http/modules/ngx_http_map_module.o \ objs/src/http/modules/ngx_http_split_clients_module.o \ objs/src/http/modules/ngx_http_referer_module.o \ objs/src/http/modules/ngx_http_rewrite_module.o \ objs/src/http/modules/ngx_http_ssl_module.o \ objs/src/http/modules/ngx_http_proxy_module.o \ objs/src/http/modules/ngx_http_fastcgi_module.o \ objs/src/http/modules/ngx_http_uwsgi_module.o \ objs/src/http/modules/ngx_http_scgi_module.o \ objs/src/http/modules/ngx_http_memcached_module.o \ objs/src/http/modules/ngx_http_empty_gif_module.o \ objs/src/http/modules/ngx_http_browser_module.o \ objs/src/http/modules/ngx_http_upstream_hash_module.o \ objs/src/http/modules/ngx_http_upstream_ip_hash_module.o \ objs/src/http/modules/ngx_http_upstream_least_conn_module.o \ objs/src/http/modules/ngx_http_upstream_keepalive_module.o \ objs/src/http/modules/ngx_http_upstream_zone_module.o \ objs/src/http/modules/ngx_http_stub_status_module.o \ objs/ngx_modules.o \ -ldl -lpthread -lcrypt -lpcre -lssl -lcrypto -ldl -lz \ -Wl,-E sed -e "s|%%PREFIX%%|/home/Nginx-1.11.5|" \ -e "s|%%PID_PATH%%|/home/Nginx-1.11.5/logs/Nginx.pid|" \ -e "s|%%CONF_PATH%%|/home/Nginx-1.11.5/conf/Nginx.conf|" \ -e "s|%%ERROR_LOG_PATH%%|/home/Nginx-1.11.5/logs/error.log|" \ < man/Nginx.8 > objs/Nginx.8 make[1]: Leaving directory `/home/Nginx'
执行安装命令 make install
make install
运行结束后,可以看到输出如下:
...... test -f '/home/Nginx-1.11.5/conf/mime.types' \ || cp conf/mime.types '/home/Nginx-1.11.5/conf' cp conf/mime.types '/home/Nginx-1.11.5/conf/mime.types.default' test -f '/home/Nginx-1.11.5/conf/fastcgi_params' \ || cp conf/fastcgi_params '/home/Nginx-1.11.5/conf' cp conf/fastcgi_params \ '/home/Nginx-1.11.5/conf/fastcgi_params.default' test -f '/home/Nginx-1.11.5/conf/fastcgi.conf' \ || cp conf/fastcgi.conf '/home/Nginx-1.11.5/conf' cp conf/fastcgi.conf '/home/Nginx-1.11.5/conf/fastcgi.conf.default' test -f '/home/Nginx-1.11.5/conf/uwsgi_params' \ || cp conf/uwsgi_params '/home/Nginx-1.11.5/conf' cp conf/uwsgi_params \ '/home/Nginx-1.11.5/conf/uwsgi_params.default' test -f '/home/Nginx-1.11.5/conf/scgi_params' \ || cp conf/scgi_params '/home/Nginx-1.11.5/conf' cp conf/scgi_params \ '/home/Nginx-1.11.5/conf/scgi_params.default' test -f '/home/Nginx-1.11.5/conf/Nginx.conf' \ || cp conf/Nginx.conf '/home/Nginx-1.11.5/conf/Nginx.conf' cp conf/Nginx.conf '/home/Nginx-1.11.5/conf/Nginx.conf.default' test -d '/home/Nginx-1.11.5/logs' \ || mkdir -p '/home/Nginx-1.11.5/logs' test -d '/home/Nginx-1.11.5/logs' \ || mkdir -p '/home/Nginx-1.11.5/logs' test -d '/home/Nginx-1.11.5/html' \ || cp -R html '/home/Nginx-1.11.5' test -d '/home/Nginx-1.11.5/logs' \ || mkdir -p '/home/Nginx-1.11.5/logs' make[1]: Leaving directory `/home/Nginx'
开启Nginx进程(注意应该输入自己的安装目录,题主此处为/home/Nginx-1.11.5/)
/home/Nginx-1.11.5/sbin/Nginx
可以通过查看进行中是否有Nginx来判断Nginx是否启动成功:
ps -ef | grep Nginx
如果发现结果中有Nginx的进程,则认为已经启动:
root 6088 1 0 18:05 ? 00:00:00 Nginx: master process /home/Nginx-1.11.5/sbin/Nginx nobody 6089 6088 0 18:05 ? 00:00:00 Nginx: worker process root 6125 1198 0 18:06 pts/0 00:00:00 grep Nginx
Nginx的重启或者关闭(s参数代表signal,向Nginx主进程发送信号):
/home/Nginx-1.11.5/sbin/Nginx -s reload /home/Nginx-1.11.5/sbin/Nginx -s stop
浏览器输入IP,即可访问到Nginx的欢迎界面: