nginx安装配置入门

// yum -y install gcc gcc-c++ autoconf automake

// yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel (安装依赖zlib、openssl和pcre)

 

1.下载nginx安装包及安装依赖包
============================================================
2.安装PCRE库
cd /usr/local/
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.33.tar.gz
tar -zxvf pcre-8.33.tar.gz
cd pcre-8.33
./configure
make
make install
如果编译rcpe报错make: *** No targets specified and no makefile found. Stop.
yum install gcc gcc-c++ autoconf automake
编译这个错误没关系 make[1]: Leaving directory `/usr/local/
============================================================
3.安装zlib库
cd /usr/local/
wget http://zlib.net/zlib-1.2.8.tar.gz
tar -zxvf zlib-1.2.8.tar.gz cd zlib-1.2.8
./configure
make
make install
============================================================
4.安装ssl
cd /usr/local/
wget http://www.openssl.org/source/openssl-1.0.1c.tar.gz
tar -zxvf openssl-1.0.1c.tar.gz
./config
make
make install
============================================================
5.安装nginx
cd /usr/local/
wget http://nginx.org/download/nginx-1.2.8.tar.gz
tar -zxvf nginx-1.2.8.tar.gz
cd nginx-1.2.8
./configure --prefix=/usr/local/nginx
make
make install

--with-pcre=/usr/src/pcre-8.21 指的是pcre-8.33 的源码路径。
--with-zlib=/usr/src/zlib-1.2.7 指的是zlib-1.2.7 的源码路径。
============================================================
6.启动
确保系统的 80 端口没被其他程序占用,
/usr/local/nginx/sbin/nginx
检查是否启动成功:
netstat -ano|grep 80 有结果输入说明启动成功
打开浏览器访问此机器的 IP,如果浏览器出现 Welcome to nginx! 则表示 Nginx 已经安装并运行成功。
否则查看防火墙
出现这个错误 error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory
ldd $(which /usr/local/nginx/sbin/nginx)
可以看出 libpcre.so.1 => not found 并没有找到,进入/lib64目录中手动链接下
cd lib64/
ln -s libpcre.so.0.0.1 libpcre.so.1
============================================================
7.重启
/usr/local/nginx/sbin/nginx –s reload
============================================================
8.修改配置文件
cd /usr/local/nginx/conf
vi nginx.conf
9.转发模版
http{
upstream www.yafan.com{
server 127.0.0.1:8081;
}
}
server {
listen 80;
server_name www.yafan.com;

#charset koi8-r;

#access_log logs/host.access.log main;

location / {
proxy_pass http://www.yafan.com;
}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}

}

posted @ 2016-11-08 11:35  不做大哥很多年  阅读(130)  评论(0编辑  收藏  举报