nginx安装及配置

1 centos 系统版本系统

[[email protected] nginx-1.11.2]# cat /etc/redhat-release 

CentOS release 6.8 (Final)
[[email protected] nginx-1.11.2]# uname -r

2.6.32-642.el6.x86_64

2 安装openssl和pcre

[[email protected] nginx-1.11.2]# yum install openssl openssl-devel pcre pcre-devel -y

[[email protected] nginx-1.11.2]# rpm -aq openssl openssl pcre pcre-devel
pcre-devel-7.8-7.el6.x86_64
pcre-7.8-7.el6.x86_64
openssl-1.0.1e-57.el6.x86_64


3 添加www用户和组

[[email protected] nginx-1.11.2]# groupadd www
[[email protected] nginx-1.11.2]# useradd www -s /sbin/nologin -M -g www

4 安装nginx

[[email protected] nginx-1.11.2]# ./configure --prefix=/application/nginx-1.11.2 --user=www --group=www --with-http_stub_status_module --with-http_ssl_module
[[email protected] nginx-1.11.2]# make 

[[email protected] nginx-1.11.2]# make install


5 系统相关配置

[[email protected] nginx-1.11.2]# /etc/init.d/iptables stop         #关闭防火墙

[[email protected] nginx-1.11.2]# ln -s /application/nginx-1.11.2/ /application/nginx    #软链接

[[email protected] nginx-1.11.2]# echo '/application/nginx/sbin/nginx' >>/etc/rc.local   #开机自动启动nginx
[[email protected] nginx-1.11.2]# tail -1 /etc/rc.local                                      #查看配置/etc/rc.load
/application/nginx/sbin/nginx
[[email protected] nginx-1.11.2]# /application/nginx/sbin/nginx             #启动nginx
[[email protected] nginx-1.11.2]# lsof :i 80 #查看启动情况

COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
nginx   4180 root    6u  IPv4  17490      0t0  TCP *:http (LISTEN)
nginx   4181  www    6u  IPv4  17490      0t0  TCP *:http (LISTEN)                     


6 测试结果

浏览器测试结果:nginx安装及配置

CURL测试:

[[email protected] nginx-1.11.2]# curl 127.0.0.1
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>


<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>


<p><em>Thank you for using nginx.</em></p>
</body>
</html>


nginx安装及配置nginx安装及配置