nginx安装配置

一般我们都需要先装pcre, zlib,前者为了重写rewrite,后者为了gzip压缩。

1.选定安装文件所在目录

选定目录 /mnt/disk/tools

cd /mnt/disk/tools

2.安装PCRE

cd /mnt/disk/tools

tar -zxvf pcre-8.21.tar.gz

cd pcre-8.21

./configure   --prefix=/usr/local/pcre

make

make install

3.安装zlib

cd /mnt/disk/tools

tar -zxvf zlib-1.2.8.tar.gz cd zlib-1.2.8

./configure --prefix=/usr/local/zlib

make

make install

4.安装ssl

cd /mnt/disk/tools

tar -zxvf openssl-1.0.1c.tar.gz

./config --prefix=/usr/local/openssl

make

make install

5.安装nginx

Nginx 一般有两个版本,分别是稳定版和开发版,您可以根据您的目的来选择这两个版本的其中一个,下面是把 Nginx 安装到 /usr/local/nginx 目录下的详细步骤:

cd /mnt/disk/tools

tar -zxvf nginx-1.2.8.tar.gz

cd nginx-1.2.8  

./configure --user=nobody --group=nobody --prefix=/usr/local/nginx
--with-http_stub_status_module --with-http_gzip_static_module
--with-http_realip_module --with-http_sub_module
--with-pcre=/mnt/disk1/tools/pcre-8.33 --with-http_ssl_module --with-openssl=/mnt/disk1/tools/openssl-1.0.1e
--with-zlib=/mnt/disk1/tools/zlib-1.2.8

make

make install

##--with-pcre=/mnt/disk/tools/pcre-8.33 指的是pcre-8.33 的源码路径。

##--with-zlib=/mnt/disk/tools/zlib-1.2.8 指的是zlib-1.2.8 的源码路径。

6.启动

确保系统的 80 端口没被其他程序占用,

/usr/local/nginx/sbin/nginx

检查是否启动成功:

netstat -ano|grep 80 有结果输入说明启动成功

打开浏览器访问此机器的 IP,如果浏览器出现 Welcome to nginx! 则表示 Nginx 已经安装并运行成功。

nginx 相关命令:

#启动

./nginx

#停止

./nginx –s stop

#重新加载

./nginx –s reload

#测试配置文件

./nginx -t

原文地址:https://www.cnblogs.com/lcxdever/p/4221548.html