Nginx是一个高性能的HTTP和反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like 协议下发行。其特点是占有内存少,并发能力强,事实上nginx的并发能力确实在同类型的网页服务器中表现较好
安装
下面我们来在centos6.8的服务器上安装一下nginx服务,首先安装nginx服务需要安装很多依赖关系
[root@koby2 ~]#yum -y install gcc gcc-c++ make libtool zlib zlib-devel openssl openssl-devel pcre pcre-devel autoconf automake
这里我们要下载一下openssl
[root@koby2 ~]#wget -O openssl.tar.gz -c https://github.com/openssl/openssl/archive/OpenSSL_1_0_2k.tar.gz #具体版本可根据实际情况选择
[root@koby2 ~]#tar zxf openssl.tar.gz
[root@koby2 ~]#mv openssl-OpenSSL_1_0_2k/ openssl
接下来我们要下载nginx 在这个网站下载需要的nginx版本http://nginx.org/en/download.html
[root@koby2 ~]#wget -c https://nginx.org/download/nginx-1.11.13.tar.gz
[root@koby2 ~]#tar -zxvf nginx-1.11.13.tar.gz
[root@koby2 ~]#cd nginx-1.11.13
[root@koby2 nginx-1.11.13]#./configure --prefix=/usr/local/nginx/ --with-openssl=/root/openssl --with-http_v2_module --with-http_ssl_module --with-http_gzip_static_module --with-http_stub_status_module --with-file-aio --with-http_realip_module
[root@koby2 nginx-1.11.13]#make && make install
我们需要配置防火墙的端口
[root@koby2 ~]# vi /etc/sysconfig/iptables
在里面添加
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
然后重启防火墙
[root@koby2 ~]# service iptables restart
这时我们来启动nginx来看看效果
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
[root@koby2 ~]# netstat -ntlp|grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 11086/nginx
可以看到nginx的端口已经在监听了 我们先在浏览器上查看下
在浏览器上输入http://192.168.1.1/ #本机ip
可以看到如下页面
Welcome to nginx!
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.
For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.
Thank you for using nginx.
这样我们的nginx就安装好了 我们再开看下改如何关闭nginx
[root@koby2 ~]# /usr/local/nginx/sbin/./nginx -s stop
重启命令如下
[root@koby2 ~]# /usr/local/nginx/sbin/nginx -s reload
检查配置文件是否正确很有帮助的一个命令
[root@koby2 ~]# /usr/local/nginx/sbin/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