前言
nginx安装之前一定要确定是否已经安装了必备的依赖库,nginx基本的依赖库有pcre、zlib、openssl这三个,这三个是一定要安装的。
一、安装pcre
wget https://ftp.pcre.org/pub/pcre/pcre-8.42.tar.gz
cd /home/user/下载/
tar -zxvf pcre-8.42.tar.gz
cd pcre-8.42
./configure
make
make install
二、安装openssl
wget https://www.openssl.org/source/openssl-1.1.1.tar.gz
cd /home/user/下载/
tar -zxvf openssl-1.1.1.tar.gz
./config
make
make install
三、安装zlib
在http://www.zlib.net/上可以获取当前最新的版本,但国内进不去,我已经下载好了。
自行下载或者联系我!懒得粘链接而已~
sudo apt install zlib1g-dev (这个也行)
四、 下载 fastdfs-nginx-module 模块
下载地址为:https://github.com/happyfish100/fastdfs-nginx-module/releases 我这里选择 V1.20 版本和fastDFS5.12版本匹配。
版本不对应可能会给接下来的安装带来各种问题(别问我怎么知道的!!!)。
# 下载 V1.20 版本
wget https://github.com/happyfish100/fastdfs-nginx-module/archive/V1.20.tar.gz
# 解压
tar -zxvf V1.20.tar.gz
五、修改 fastdfs-nginx-module配置文件
编辑 fastdfs-nginx-module-1.20/src/config 文件。通过关键字 ngx_module_incs 和 CORE_INCS 找到下面两行。
ngx_module_incs="/usr/local/include"
CORE_INCS="$CORE_INCS /usr/local/include"
替换成:
ngx_module_incs="/usr/include/fastdfs /usr/include/fastcommon/"
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
六、下载nginx并整合 fastdfs-nginx-module 模块
# 下载 Nginx
wget http://nginx.org/download/nginx-1.14.2.tar.gz
# 解压
tar -zxvf nginx-1.14.2.tar.gz
# 进入目录
cd nginx-1.14.2/
# 配置 nginx 安装位置/usr/local/nginx 和 fastdfs-nginx-module-1.20/src 依赖模块的路径
./configure --prefix=/usr/local/nginx --add-module=/home/zt/Desktop/fastdfs-nginx-module-1.20/src
# 编译 nginx(版本不对应,这里有问题!)
make
# 安装
sudo make install
七、复制并修改 mod_fastdfs.conf 配置文件
进入解压的 fastdfs-nginx-module-1.20 目录
# 将 mod_fastdfs.conf 文件拷贝到 /etc/fdfs/ 目录
sudo cp mod_fastdfs.conf /etc/fdfs/
修改 mod_fastdfs.conf 配置文件
connect_timeout=10 # 超时时间
base_path=/home/zt/Desktop/fastdfs_work/log # 保存日志目录
tracker_server=虚拟机Ip:22122 # tracker 服务器
storage_server_port=23000 # storage 服务器端口
url_have_group_name=true # url包含组名
store_path0=/home/zt/Desktop/fastdfs_work/storage0 # 存储上传文件的目录
八、配置软连接
sudo ln -s /home/zt/Desktop/fastdfs_work/storage0/data/ /home/zt/Desktop/fastdfs_work/storage0/data/M00
目的是通过nginx反向代理带真实存储文件的路径。
九、修改 nginx.conf 配置文件
修改 /usr/local/nginx/conf/nginx.conf 配置文件
server {
listen 8080; (必须和 storage.conf 配置文件中的 http.server_port 属性值一样)
server_name 虚拟机Ip;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
location ~/group([0-9])/M00 {
root /home/zt/Desktop/fastdfs_work/storage0/data;
ngx_fastdfs_module;
}
...
}
十、 启动 nginx
sudo /usr/local/nginx/sbin/nginx
启动成功会显示 ngx_http_fastdfs_set pid=xxx 字样,说明和 fastdfs-nginx-module 模块整合成功!!
十一、访问已上传的文件
http://192.168.206.129:8080/group1/M00/00/00/wKjkgF4do16AKlVuAABuV-mil-o911_big.jpg
如下图:
到此结束,成功了!
来源:CSDN
作者:Be super
链接:https://blog.csdn.net/weixin_41826895/article/details/103988410