您的位置:首页 > 运维架构 > Nginx

删:Centos 7安装Nginx 1.8

2016-01-22 16:59 549 查看

[CentOS 7] 安装nginx

首先进行 nginx yum

Nginx安装记录

注意:如果用源码安装,nginx配置时需要指定--with-pcer对应的压缩包路径,如果使用二进制安装不需要指定

依赖包使用二进制yum一键安装:yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel

一键安装开发工具包:yum -y groupinstall "Development Tools" "Development Libraries"

下载Nginx
http://nginx.org/download/nginx-1.8.0.tar.gz
Nginx安装所需依赖包

1、rewrite模块需要pcre库(下载: http://www.pcre.org) 支持nginx伪静态

2、ssl模块需要openssl库(下载: http://www.openssl.org) nginx扩展

3、gzip模块需要zlib库(下载:http://www.zlib.net) nginx扩展

编译安装Nginx所需依赖包

pcre:

tar zxvf pcre-8.38.tar.gz

cd pcre-8.38/

./configure --prefix=/usr/local/pcre

make

make install

openssl:

tar zxvf openssl-1.0.2e.tar.gz

cd openssl-1.0.2e/

*注意此处

./config --prefix=/usr/local/openssl

make&&make install

tar zxvf zlib-1.2.8.tar.gz

cd zlib-1.2.8/

./configure --prefix=/usr/local/zlib

make&&make install

安装Nginx

groupadd -r nginx

useradd -r -g nginx -s /bin/false -M nginx

tar zxvf nginx-1.8.0.tar.gz

cd nginx-1.8.0/

./configure --prefix=/usr/local/nginx \ set installation prefix

--without-http_memcached_module \ disable ngx_http_memcached_module

--user=nginx \ set non-privileged user for worker processes

--group=nginx \ set non-privileged group for worker processes

--with-http_stub_status_module \ 取得一些nginx的运行状态

--with-http_ssl_module \ 开启HTTP SSL模块,以支持HTTPS请求。

--with-http_gzip_static_module \ 预压缩文件传输前检查,防止文件被重复压缩

--with-pcre=/home/eric/pcre-8.38 \ *路径指向解压源码所在的目录

--with-openssl=/home/eric/openssl-1.0.2d \ *路径指向解压源码所在的目录

--with-zlib=/home/eric/zlib-1.2.8 *路径指向解压源码所在的目录

make

make install

*注:编译好后可通过/usr/local/nginx/sbin/nginx -V (Nginx安装的路径)查看编译时候的参数

启动Nginx服务

cd /usr/local/nginx/

nginx -c /etc/nginx/nginx.conf

参数“-c”指定了Nginx配置文件的路径,如果不加“-c”参数,Nginx会默认加载其安装目录的conf子目录中的nginx.conf文件.

nginx安装 nginx: [emerg] getpwnam(“www”) failed 错误

附加:

查看监听端口netstat -nptl

nginx启动、重启、关闭
一、启动  
cd usr/local/nginx/sbin
./nginx
二、重启
  更改配置重启nginx  
kill -HUP 主进程号或进程号文件路径
或者使用
cd /usr/local/nginx/sbin
./nginx -s reload
判断配置文件是否正确 
nginx -t -c /usr/local/nginx/conf/nginx.conf
或者
cd  /usr/local/nginx/sbin
./nginx -t
三、关闭
  查询nginx主进程号
  ps -ef | grep nginx
  从容停止   kill -QUIT 主进程号
  快速停止   kill -TERM 主进程号
  强制停止   kill -9 nginx
  若nginx.conf配置了pid文件路径,如果没有,则在logs目录下
  kill -信号类型 '/usr/local/nginx/logs/nginx.pid'
四、升级
  1、先用新程序替换旧程序文件
  2、kill -USR2 旧版程序的主进程号或者进程文件名
    此时旧的nginx主进程会把自己的进程文件改名为.oldbin,然后执行新版nginx,此时新旧版本同时运行
  3、kill -WINCH 旧版本主进程号
  4、不重载配置启动新/旧工作进程
    kill -HUP 旧/新版本主进程号
    从容关闭旧/新进程
    kill -QUIT 旧/新进程号
    快速关闭旧/新进程
    kill -TERM 旧/新进程号

Nginx关闭版本信息显示

nginx出错会在http头显示醒目的版本号提示,为了安全需要关闭这些信息。

方法很简单,只需在nginx.conf的http中加入server_tokens参数

http {

include mime.types;

default_type application/octet-stream;

server_tokens off;

}

防火墙

Centos 7默认启用Firewalld

访问Nginx需要开放80端口

firewall-cmd --permanent --add-service=http

firewall-cmd --permanent --zone=trusted --add-port=80/tcp
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: