一 、环境准备
1. 下载nginx
下载地址:http://nginx.org/en/download.html
2.上传到虚拟机上,并解压
tar-zxvf nginx-1.8.1.tar.gz
3.安装准备插件
yum -y install pcre-devel openssl openssl-devel
二 、安装nginx
1.进入nginx目录并输入以下命令进行配置:
./configure --prefix=/usr/local/nginx --add-module=/usr/local/fastdfs-nginx-module-master/src
配置成功后会看到如下信息:

2.进行编译安装,依次执行以下命令:
make
make install
安装完成后,我们在我们指定的目录/usr/local/nginx中就可以看到nginx的安装目录了:

三 、配置文件的修改
1. 进入nginx安装目录的conf目录下,修改nginx.conf文件,在一个server{}中添加 一个location 部分配置代码如下
user root; //此处写在最上方 root@ubuntu:/usr/local/nginx/conf# vi nginx.conf server { listen 80; server_name localhost; location / { root html; index index.html index.htm; } //以下为要添加的内容 location /hello/ { root /usr/local/helloWorld/; autoindex on; } } |
2. 在nginx安装目录的html目录中新建一个 与 location中 image同名的image目录,虽然该目录里面什么也没有,
在/usr/local/helloWorld/hello/中我们放一张图片1.jpg上去,重启nginx服务,就可以通过 localhost:80/image/1.jpg访问了
root@ubuntu:/usr/local/nginx/html# mkdir hello root@ubuntu:/usr/local/nginx/html# mkdir /usr/local/helloWorld/hello #放一张照片上去# root@ubuntu:/usr/local/nginx/html# cd /usr/local/helloWorld/hello root@ubuntu:/usr/local/helloWorld/hello# ls 1.jpg root@ubuntu:/usr/local/helloWorld/hello# |
root@ubuntu:/usr/local/nginx/sbin# ./nginx
**********************************************************
安装Nginx时报错 1.错误提示./configure: error: the HTTP rewrite module requires the PCRE library. 安装pcre-devel解决问题 yum -y install pcre-devel 2.错误提示:./configure: error: the HTTP cache module requires md5 functions from OpenSSL library. You can either disable the module by using --without-http-cache option, or install the OpenSSL library into the system, or build the OpenSSL library statically from the source with nginx by using --with-http_ssl_module --with-openssl=<path> options. 解决办法: yum -y install openssl openssl-devel 3.错误提示:error: the HTTP gzip module requires the zlib library 解决办法 yum install -y zlib-devel