安装nginx

准备

  • 编译环境:yum install gcc-c++
  • 正则表达式库:yum install -y pcre pcre-devel
  • 解/压缩库:yum install -y zlib zlib-devel
  • 套接字密码库:yum install -y openssl openssl-devel

安装

下载:wget -c https://nginx.org/download/nginx-1.12.0.tar.gz

解压:tar -zxvf nginx-1.12.0.tar.gz

cd nginx-1.12.0

配置:

  • ./configure (默认配置)
  • 自定义配置:(按需选择配置方式)

./configure \

--prefix=/usr/local/nginx \

--pid-path=/var/run/nginx/nginx.pid \

--lock-path=/var/lock/nginx.lock \

--error-log-path=/var/log/nginx/error.log \

--http-log-path=/var/log/nginx/access.log \

--with-http_gzip_static_module \

--http-client-body-temp-path=/var/temp/nginx/client \

--http-proxy-temp-path=/var/temp/nginx/proxy \

--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \

--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \

--http-scgi-temp-path=/var/temp/nginx/scgi

注:将临时文件目录指定为/var/temp/nginx,需要在/var下创建temp及nginx目录(mkdir -p /var/temp/nginx)

编译安装:

  • make
  • make install

启动

  • cd /usr/local/nginx/sbin/
  • ./nginx
  • ./nginx -s stop停止
  • ./nginx -s quit完整停止

  • ./nginx -s reload重新加载配置(启动状态下使用)

  • 开机自启

vi /etc/rc.local
添加:/usr/local/nginx/sbin/nginx<br />chomd <code class="hljs perl"><span><span>755 rc.<span>local</span></span></span>

测试

  • 在浏览器输入IP地址访问:192.168.x.x 注:防火墙开启80端口访问。
  • 配置映射路径
  1. vi /usr/local/nginx/conf/nginx.conf
  2. root:映射路径;autoindex:打开浏览功能

例子:location /images/{

root /home/ftpuser/www/;

autoindex on;

}

注:需在/usr/local/nginx/html下创建images目录

ngnix配置图片服务器——配置路径(centos7)