编译环境准备
ubuntu
apt-get install build-essential
apt-get install libtool
CentOS
#安装make
yum -y install gcc automake autoconf libtool make
#安装g++
yum install gcc gcc-c++
#安装PCRE库
yum install -y pcre pcre-devel
#安装zlib库
yum install -y zlib zlib-devel
##也可一步完成
yum install -y gcc gcc-c++ pcre pcre-devel zlib zlib-devel
开始安装
cd /usr/local/nginx
wget http://nginx.org/download/nginx-1.4.2.tar.gz
tar -zxvf nginx-1.4.2.tar.gz
cd nginx-1.4.2
./configure --prefix=/usr/local/nginx/nginx-1.4.2 \
--conf-path=/usr/local/nginx/nginx.conf \
--pid-path=/usr/local/nginx/nginx.pid
make
make install
安装成功后 /usr/local/nginx 目录下如下
[root@localhost nginx]# ls
fastcgi.conf fastcgi_params koi-utf mime.types nginx-1.4.2 nginx.conf.default scgi_params.default uwsgi_params.default
fastcgi.conf.default fastcgi_params.default koi-win mime.types.default nginx.conf scgi_params uwsgi_params win-utf
启动Nginx
确保系统的 80 端口没被其他程序占用,运行/usr/local/nginx/nginx-1.4.2/sbin/nginx命令来启动 Nginx
cd /usr/local/nginx/nginx-1.4.2/sbin
./nginx -c /usr/local/nginx/conf/nginx.conf
#也可以直接启动
./nginx
查看是否启动完成
查看进程
[root@localhost sbin]# ps -ef|grep nginx
root 1343 1 0 20:09 ? 00:00:00 nginx: master process ./nginx
nobody 1344 1343 0 20:09 ? 00:00:00 nginx: worker process
root 1346 1325 0 20:09 pts/0 00:00:00 grep --color=auto nginx
本机访问
[root@localhost sbin]# curl localhost
<!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>