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

nginx编译安装

2016-06-22 14:42 357 查看

nginx编译安装

开始前准备

环境需求

当前在centos6.7系统环境下进行的Nginx编译安装

编译安装nginx所需要用到的系统基本库

yum -y install wget curl gcc gcc-c++ perl

nginx编译安装需要的相关包下载

nginx源码包

wget -c http://nginx.org/download/nginx-1.10.1.tar.gz[/code] openssl包用于ssl协议支持

wget -c https://www.openssl.org/source/openssl-1.0.2h.tar.gz[/code] zlib包用于压缩模块

wget -c http://zlib.net/zlib-1.2.8.tar.gz[/code] 

编译安装

tar zxf nginx-1.10.1.tar.gz
cd nginx-1.10.1
./configure --prefix=/usr/local/nginx-1.10.1 --with-http_stub_status_module --with-http_sub_module --with-http_ssl_module --with-pcre=../pcre-8.39 --with-http_realip_module --with-http_gzip_static_module --with-zlib=../zlib-1.2.8 --with-openssl=../openssl-1.0.2h

make && make install

启动nginx

查看80端口是否被启用

netstat -ntlp |grep 80

启动nginx

/usr/local/nginx-1.10.1/sbin/nginx

测试访问

curl 127.0.0.1
将返回如下信息,表示安装成功
[root@bogon nginx-1.10.1]# 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支持html,要支持php访问,还需要安装php

后话

如果启用了iptables规则,可能要开放80端口访问

vi /etc/sysconfig/iptables
加入一条规则到下面位置,如下所示

# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT

然后重启iptables

service iptables restart

相关的库如openssl,zlib,pcre也可以通过yum进行安装

yum -y install zlib-devel openssl openssl-devel pcre-devel
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: