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

Nginx 的安装, 环境是CentOS

2015-10-17 22:41 399 查看
nginx is an HTTP and reverse proxy server, a mail proxy server, and a generic TCP proxy server.

官网地址为:http://nginx.org/en/

下面是在CentOS7上面安装Nginx步骤,供参考

环境准备

Nginx有几个依赖的包,分别是:

1). openssl, nginx的ssl功能需要此组件,实现一些安全方面的业务。

资源地址: http://www.openssl.org/

2). zlib, 提供相关数据压缩服务。

资源地址: http://www.zlib.net/

3). pcre, 提供Nginx请求拦截时的正则匹配功能。

介绍在此: http://www.pcre.org/

下载地址: ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/

最后是Nginx的源码安装文件,http://nginx.org/en/download.html

安装步骤

1) 安装openssl依赖

[hinsteny@localhost nginx]$ tar -zxf openssl-1.0.2d.tar.gz
[hinsteny@localhost openssl-1.0.2d]$ sudo ./config
[hinsteny@localhost openssl-1.0.2d]$ sudo make
[hinsteny@localhost openssl-1.0.2d]$ sudo make install


2) 安装zlib依赖

[hinsteny@localhost nginx]$ tar -xf zlib-1.2.8.tar.gz
[hinsteny@localhost zlib-1.2.8]$ sudo ./configure
[hinsteny@localhost zlib-1.2.8]$ sudo make
[hinsteny@localhost zlib-1.2.8]$ sudo make install


3) 安装pcre依赖

[hinsteny@localhost nginx]$ tar -xzf pcre-8.37.tar.gz
[hinsteny@localhost pcre-8.37]$ sudo ./configure
[hinsteny@localhost pcre-8.37]$ sudo make
[hinsteny@localhost pcre-8.37]$ sudo make install


4) 最后就是安装主角,Nginx咯,关于nginx的编译安装,关于nginx的编译配置可以参考前面所给的官方地址里的介绍,这里只给出一个配置示例

[hinsteny@localhost nginx]$ tar -xzf nginx-1.9.5.tar.gz
[hinsteny@localhost nginx-1.9.5]$  sudo ./configure --with-http_ssl_module --with-openssl=../openssl-1.0.2d --with-pcre=../pcre-8.37 --with-zlib=../zlib-1.2.8
[hinsteny@localhost nginx-1.9.5]$  sudo make
[hinsteny@localhost nginx-1.9.5]$  sudo make install


5) 最后验证下Nginx是否安装成功,

[hinsteny@localhost nginx-1.9.5]$ cd /usr/local/nginx/sbin/
[hinsteny@localhost sbin]$ sudo ./nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[hinsteny@localhost sbin]$ sudo ./nginx (启动Nginx)
[hinsteny@localhost sbin]$ netstat -ntlp (查看端口)
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      -
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      -
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      -
tcp6       0      0 :::22                   :::*                    LISTEN      -
tcp6       0      0 ::1:631                 :::*                    LISTEN      -
tcp6       0      0 ::1:25                  :::*                    LISTEN      -


6) 如果每次都进去Nginx的目录去启动或者重启,重载配置那也太麻烦了吧,那我们可以建立一个软连接,那也就可以在任意地方调用Nginx服务命令了啊

[hinsteny@localhost sbin]$ sudo ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx
[hinsteny@localhost bin]$ sudo nginx -s reload  (重启)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  nginx ssl