centos7 安装 nginx1.9.2

简介: 一、准备工作: 1、安装必备工具: $ yum -y install gcc gcc-c++ autoconf automake $ yum -y install zlib zlib-devel openssl openssl-devel pcre-devel ? 说明: pcre: 用来作地址重写的功能。 zlib

一、准备工作:

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、新建一个系统级用户组和匿名用户,以及下面编译时使用

$ sudo groupadd -r nginx
 
$ sudo useradd -s /sbin/nologin -g nginx -r nginx-user


?

二、Nginx编译安装:

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

2、解压编译:

$ tar -zxvf nginx-1.9.2.tar.gz
 
$ cd nginx-1.9.2/


./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_64
checking 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 ... found
checking for gcc builtin atomic operations ... found
checking for C99 variadic macros ... found
checking for gcc variadic macros ... 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 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 sched_setaffinity() ... found
checking for crypt_r() ... found
checking for sys/vfs.h ... 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 SO_SETFIB ... not found
checking for SO_REUSEPORT ... found
checking for SO_ACCEPTFILTER ... not found
checking for TCP_DEFER_ACCEPT ... found
checking for TCP_KEEPIDLE ... found
checking for TCP_FASTOPEN ... not found
checking for TCP_INFO ... found
checking for accept4() ... found
checking for eventfd() ... 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 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 setproctitle() ... not found
checking for pread() ... found
checking for pwrite() ... 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 ... found
checking for OpenSSL library ... found
checking for zlib library ... found
creating objs/Makefile
 
Configuration 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、启动:

nginx -c /etc/nginx/nginx.conf
修改配置文件后重新加载,无需重启
nginx -c /etc/nginx/nginx.conf -s reload



?

如果提示缺什么包,直接用yum安装

 yum installxxxxx


?


(1)如果提示:
nginx: [emerg] mkdir() "/var/tmp/nginx/client_temp" failed (2: No such file or directory)
则用管理员去mkdir  /var/tmp/nginx文件夹 后再启动。




(2)在配置nginx 时提示如下错误时:
nginx: [emerg] getpwnam(“www”) failed

解决方案一
在nginx.conf中 把user nobody的注释去掉既可

解决方案二

错误的原因是没有创建www这个用户,应该在服务器系统中添加www用户组和用户www,如下命令:

/usr/sbin/groupadd -f www
/usr/sbin/useradd -g www www


对于nginx的操作,指令比较长,也不便于操作,因此可以使用脚本,教程中转:


CentOS 7 Nginx 控制脚本

附加1:

?
--help                             print this message
 
  --prefix=PATH                     setinstallation prefix
  --sbin-path=PATH                  setnginx binary pathname
  --conf-path=PATH                  setnginx.conf pathname
  --error-log-path=PATH             seterror log pathname
  --pid-path=PATH                   setnginx.pid pathname
  --lock-path=PATH                  setnginx.lock pathname
 
  --user=USER                       setnon-privileged user for
                                     worker processes
  --group=GROUP                     setnon-privileged group for
                                     worker processes
 
  --build=NAME                      setbuild name
  --builddir=DIR                    setbuild directory
 
  --with-select_module              enableselect module
  --without-select_module            disable selectmodule
  --with-poll_module                enablepoll module
  --without-poll_module              disable poll module
 
  --with-threads                    enablethread pool support
 
  --with-file-aio                   enablefile AIO support
  --with-ipv6                       enableIPv6 support
 
  --with-http_ssl_module            enablengx_http_ssl_module
  --with-http_spdy_module           enablengx_http_spdy_module
  --with-http_realip_module         enablengx_http_realip_module
  --with-http_addition_module       enablengx_http_addition_module
  --with-http_xslt_module           enablengx_http_xslt_module
  --with-http_image_filter_module   enablengx_http_image_filter_module
  --with-http_geoip_module          enablengx_http_geoip_module
  --with-http_sub_module            enablengx_http_sub_module
  --with-http_dav_module            enablengx_http_dav_module
  --with-http_flv_module            enablengx_http_flv_module
  --with-http_mp4_module            enablengx_http_mp4_module
  --with-http_gunzip_module         enablengx_http_gunzip_module
  --with-http_gzip_static_module    enablengx_http_gzip_static_module
  --with-http_auth_request_module   enablengx_http_auth_request_module
  --with-http_random_index_module   enablengx_http_random_index_module
  --with-http_secure_link_module    enablengx_http_secure_link_module
  --with-http_degradation_module    enablengx_http_degradation_module
  --with-http_stub_status_module    enablengx_http_stub_status_module
 
  --without-http_charset_module      disable ngx_http_charset_module
  --without-http_gzip_module         disable ngx_http_gzip_module
  --without-http_ssi_module          disable ngx_http_ssi_module
  --without-http_userid_module       disable ngx_http_userid_module
  --without-http_access_module       disable ngx_http_access_module
  --without-http_auth_basic_module   disable ngx_http_auth_basic_module
  --without-http_autoindex_module    disable ngx_http_autoindex_module
  --without-http_geo_module          disable ngx_http_geo_module
  --without-http_map_module          disable ngx_http_map_module
  --without-http_split_clients_module disable ngx_http_split_clients_module
  --without-http_referer_module      disable ngx_http_referer_module
  --without-http_rewrite_module      disable ngx_http_rewrite_module
  --without-http_proxy_module        disable ngx_http_proxy_module
  --without-http_fastcgi_module      disable ngx_http_fastcgi_module
  --without-http_uwsgi_module        disable ngx_http_uwsgi_module
  --without-http_scgi_module         disable ngx_http_scgi_module
  --without-http_memcached_module    disable ngx_http_memcached_module
  --without-http_limit_conn_module   disable ngx_http_limit_conn_module
  --without-http_limit_req_module    disable ngx_http_limit_req_module
  --without-http_empty_gif_module    disable ngx_http_empty_gif_module
  --without-http_browser_module      disable ngx_http_browser_module
  --without-http_upstream_hash_module
                                     disable ngx_http_upstream_hash_module
  --without-http_upstream_ip_hash_module
                                     disable ngx_http_upstream_ip_hash_module
  --without-http_upstream_least_conn_module
                                     disable ngx_http_upstream_least_conn_module
  --without-http_upstream_keepalive_module
                                     disable ngx_http_upstream_keepalive_module
  --without-http_upstream_zone_module
                                     disable ngx_http_upstream_zone_module
 
  --with-http_perl_module           enablengx_http_perl_module
  --with-perl_modules_path=PATH     setPerl modules path
  --with-perl=PATH                  setperl binary pathname
 
  --http-log-path=PATH              sethttp access log pathname
  --http-client-body-temp-path=PATH setpath to store
                                     http client request body temporary files
  --http-proxy-temp-path=PATH       setpath to store
                                     http proxy temporary files
  --http-fastcgi-temp-path=PATH     setpath to store
                                     http fastcgi temporary files
  --http-uwsgi-temp-path=PATH       setpath to store
                                     http uwsgi temporary files
  --http-scgi-temp-path=PATH        setpath to store
                                     http scgi temporary files
 
  --without-http                     disable HTTP server
  --without-http-cache               disable HTTP cache
 
  --with-mail                       enablePOP3/IMAP4/SMTPproxy module
  --with-mail_ssl_module            enablengx_mail_ssl_module
  --without-mail_pop3_module         disable ngx_mail_pop3_module
  --without-mail_imap_module         disable ngx_mail_imap_module
  --without-mail_smtp_module         disable ngx_mail_smtp_module
 
  --with-stream                     enableTCP proxy module
  --with-stream_ssl_module          enablengx_stream_ssl_module
  --without-stream_access_module     disable ngx_stream_access_module
  --without-stream_upstream_hash_module
                                     disable ngx_stream_upstream_hash_module
  --without-stream_upstream_least_conn_module
                                     disable ngx_stream_upstream_least_conn_module
  --without-stream_upstream_zone_module
                                     disable ngx_stream_upstream_zone_module
 
  --with-google_perftools_module    enablengx_google_perftools_module
  --with-cpp_test_module            enablengx_cpp_test_module
 
  --add-module=PATH                 enablean external module
 
  --with-cc=PATH                    setC compiler pathname
  --with-cpp=PATH                   setC preprocessor pathname
  --with-cc-opt=OPTIONS             setadditional C compiler options
  --with-ld-opt=OPTIONS             setadditional linker options
  --with-cpu-opt=CPU                 build forthe specified CPU, valid values:
                                     pentium, pentiumpro, pentium3, pentium4,
                                     athlon, opteron, sparc32, sparc64, ppc64
 
  --without-pcre                     disable PCRE library usage
  --with-pcre                        force PCRE library usage
  --with-pcre=DIR                   setpath to PCRE library sources
  --with-pcre-opt=OPTIONS           setadditional build options forPCRE
  --with-pcre-jit                    build PCRE with JIT compilation support
 
  --with-md5=DIR                    setpath to md5 library sources
  --with-md5-opt=OPTIONS            setadditional build options formd5
  --with-md5-asm                     use md5 assembler sources
 
  --with-sha1=DIR                   setpath to sha1 library sources
  --with-sha1-opt=OPTIONS           setadditional build options forsha1
  --with-sha1-asm                    use sha1 assembler sources
 
  --with-zlib=DIR                   setpath to zlib library sources
  --with-zlib-opt=OPTIONS           setadditional build options forzlib
  --with-zlib-asm=CPU                use zlib assembler sources optimized
                                     forthe specified CPU, valid values:
                                     pentium, pentiumpro
 
  --with-libatomic                   force libatomic_ops library usage
  --with-libatomic=DIR              setpath to libatomic_ops library sources
 
  --with-openssl=DIR                setpath to OpenSSL library sources
  --with-openssl-opt=OPTIONS        setadditional build options forOpenSSL
 
  --with-debug                      enabledebug logging

原文链接 http://my.oschina.net/liucao/blog/470241?fromerr=d9Kj1nub#OSC_h2_1

目录
相关文章
|
1月前
|
存储 Ubuntu Linux
VMware-安装CentOS系统教程及安装包
虚拟机相当于是一个独立于你电脑的环境,在这个环境上面,你可以安装Linux、Windows、Ubuntu等各个类型各个版本的系统,在这个系统里面你不用担心有病读等,不用担心文件误删导致系统崩溃。 虚拟机也和正常的电脑系统是一样的,也可以开关机,不用的时候,你关机就可以了,也不会占用你的系统资源,使用起来还是比较方便 这里也有已经做好的CentOS 7系统,下载下来解压后直接用VMware打开就可以使用
384 69
|
4月前
|
应用服务中间件 Linux 网络安全
Centos 8.0中Nginx配置文件和https正书添加配置
这是一份Nginx配置文件,包含HTTP与HTTPS服务设置。主要功能如下:1) 将HTTP(80端口)请求重定向至HTTPS(443端口),增强安全性;2) 配置SSL证书,支持TLSv1.1至TLSv1.3协议;3) 使用uWSGI与后端应用通信(如Django);4) 静态文件托管路径设为`/root/code/static/`;5) 定制错误页面(404、50x)。适用于Web应用部署场景。
573 87
|
1月前
|
Ubuntu Linux 索引
Centos 7、Debian及Ubuntu系统中安装和验证tree命令的指南。
通过上述步骤,我们可以在CentOS 7、Debian和Ubuntu系统中安装并验证 `tree`命令。在命令行界面中执行安装命令,然后通过版本检查确认安装成功。这保证了在多个平台上 `tree`命令的一致性和可用性,使得用户无论在哪种Linux发行版上都能使用此工具浏览目录结构。
199 78
|
2月前
|
Linux 网络安全 Apache
针对在Centos/Linux安装Apache过程中出现的常见问题集锦
以上每个问题的解决方案应深入分析错误日志、系统消息和各种配置文件,以找到根本原因并加以解决。务必保持系统和Apache软件包更新到最新版本,以修复已知的bugs和安全漏洞。安装和管理Web服务器是一项需要细致关注和不断学习的任务。随着技术的发展,推荐定期查看官方文档和社区论坛,以保持知识的更新。
165 80
|
16天前
|
存储 关系型数据库 MySQL
在CentOS 8.x上安装Percona Xtrabackup工具备份MySQL数据步骤。
以上就是在CentOS8.x上通过Perconaxtabbackup工具对Mysql进行高效率、高可靠性、无锁定影响地实现在线快速全量及增加式数据库资料保存与恢复流程。通过以上流程可以有效地将Mysql相关资料按需求完成定期或不定期地保存与灾难恢复需求。
93 10
|
4月前
|
Ubuntu 网络协议 应用服务中间件
在 Ubuntu 上安装 Nginx
在 Ubuntu 上安装和配置 Nginx 非常简单。首先更新系统包,然后通过 `apt` 安装 Nginx,检查服务状态并配置防火墙规则。访问服务器 IP 测试是否成功显示默认页面。还可管理服务、创建虚拟主机及排查常见问题,适合新手快速上手部署高性能 Web 服务。
535 0
|
28天前
|
运维 网络协议 Linux
CentOS下Bind服务的安装与故障排查
通过以上的步骤,您应该能够在CentOS系统上安装并配置BIND DNS服务,并进行基本的故障排查。
156 0
|
2月前
|
人工智能 数据挖掘 Linux
Centos安装Python3.7(亲测可用)
本指南详细介绍了在基于Linux(以CentOS系统为例,使用yum包管理器)的系统上安装Python 3.7版本的完整流程。Python是一种广泛使用的高级编程语言,在各种领域如软件开发、数据分析、人工智能和区块链开发等都有着重要的应用。
218 2
|
3月前
|
机器人 Linux
CentOS 7系统中安装特定版本CMake 3.21.2的方法。
到这里,过程已经全部完成。如果你跟随上面的步骤来,那么你现在已经拥有了一个全新的CMake版本在你的CentOS 7系统上了。这个过程就像是你通过一系列仪式,唤醒了一个沉睡已久的古老机器人,它现在完全按照你的意愿来帮你构建和编译软件了。
195 18
|
3月前
|
安全 应用服务中间件 Linux
Debian操作系统如何安装Nginx并开启HTTP2
本指南介绍了在Linux系统中通过源码编译安装Nginx的完整流程。首先更新软件包列表并安装必要的编译依赖,接着下载指定版本的Nginx源码包(如1.24.0),检查文件完整性后解压。随后通过配置脚本指定安装路径与模块(如HTTP SSL模块),执行编译和安装命令。最后创建软链接以便全局调用,并提供启动、停止及重载Nginx的命令,同时提醒注意安全组设置以确保正常访问。