1、安装Nginx
我使用yum安装Nginx需要的环境
yum install -y gcc
yum install -y gcc-c++
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel
然后在/usr/local下安装
cd /usr/local/
wget http://nginx.org/download/nginx-1.12.2.tar.gz
tar -zxvf nginx-1.12.2.tar.gz
cd nginx-1.12.2
./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-http_ssl_module
./configure --with-openssl=/usr/local
make && make install
安装完成后启动
whereis nginx
cd /usr/local/nginx/sbin
./nginx
然后直接浏览器输入机器IP即可看到Nginx欢迎页
常用命令:
访问:curl localhost
重启:./nginx -s reload
停止:./nginx -s stop
离开:./nginx -s quit
2、FastDfs 关联 Nginx
修改Nginx配置文件 /usr/local/nginx/conf 中nginx.conf
server下修改端口与fastdfs中一致
listen 8080;
location后添加group1,此处group1位fastdfs中配置使用的group,/home/fastdfs/file/data 为storage上传后文件存放的路径
location /group1 {
alias /home/fastdfs/file/data;
}
访问URL为
http://192.168.197.132:8080/group1/M00/00/00/wKjFhFxrmrOAOqbEAAKfUwEXTJ0342.jpg
我尝试去掉M00后即可访问,所以可以尝试修改URL查看配置问题
URL中端口对应,group名对应,但是M00在哪里呢
这里需要创建一个软连接,因为我们的上传后文件是在/home/fastdfs/file/data/00/00路径下的,所以讲 data/M00 指向到 data处
ln -s /home/fastdfs/file/data /home/fastdfs/file/data/M00
再次访问,OK