nginx - fastdfs - https 编译

本文介绍在包含FastDFS环境下Nginx及其模块的编译配置过程,详细列出所需环境变量及编译命令,适用于解决编译过程中出现的头文件缺失等问题。

基本编译的环境变量,不带fastdfs

export C_INCLUDE_PATH=/usr/local/addons/pcre/include:$C_INCLUDE_PATH
export LIBRARY_PATH=/usr/local/addons/pcre/lib:$LIBRARY_PATH
export C_INCLUDE_PATH=/usr/local/addons/zlib/include:$C_INCLUDE_PATH
export LIBRARY_PATH=/usr/local/addons/zlib/lib:$LIBRARY_PATH

如果加上FsatDFS的话,编译有些小复杂

# 编译的时候需要如下的那么多变量
ourPrefix="/opt/machtalk/"
export C_INCLUDE_PATH=${ourPrefix}addons/pcre/include:$C_INCLUDE_PATH
export LIBRARY_PATH=${ourPrefix}addons/pcre/lib:$LIBRARY_PATH
export C_INCLUDE_PATH=${ourPrefix}addons/zlib/include:$C_INCLUDE_PATH
export LIBRARY_PATH=${ourPrefix}addons/zlib/lib:$LIBRARY_PATH
export C_INCLUDE_PATH=${ourPrefix}addons/FastDFS/common/:$C_INCLUDE_PATH
export C_INCLUDE_PATH=${ourPrefix}addons/libfastcommon/include/:$C_INCLUDE_PATH
export LIBRARY_PATH=${ourPrefix}addons/libfastcommon/lib/:$LIBRARY_PATH
export C_INCLUDE_PATH=${ourPrefix}addons/FastDFS/client/:$C_INCLUDE_PATH
export LIBRARY_PATH=${ourPrefix}addons/FastDFS/client/:$LIBRARY_PATH
export C_INCLUDE_PATH=${ourPrefix}addons/FastDFS/storage/trunk_mgr:${ourPrefix}addons/FastDFS/tracker:$C_INCLUDE_PATH
export LIBRARY_PATH=${ourPrefix}addons/FastDFS/lib:$LIBRARY_PATH
# 编译
./configure --prefix=${ourPrefix}nginx --add-module=${ourPrefix}addons/fastdfs-nginx-module/src/ --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --with-openssl=${ourPrefix}addons/openssl
# 运行的时候,需要具备如下的变量环境
ourPrefix="/opt/software/"
export LD_LIBRARY_PATH=${ourPrefix}addons/libfastcommon/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=${ourPrefix}fastdfs/usr/lib64/:$LD_LIBRARY_PATH
export PATH=${ourPrefix}fastdfs/usr/bin:$PATH
export LD_LIBRARY_PATH=${ourPrefix}addons/libfastcommon/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=${ourPrefix}fastdfs/usr/lib64/:$LD_LIBRARY_PATH
export PATH=${ourPrefix}fastdfs/usr/bin:$PATH
export PATH=${ourPrefix}nginx/sbin:$PATH

总结:
* 如果编译的时候提示找不到.h文件,那么
* find somelujing -name “xx.h”
* 使用export C_INCLUDE_PATH=xx.h:C_INCLUDE_PATH

<think>我们正在配置Nginx以使用fastdfs-nginx-module模块。根据引用[1]和引用[3]的信息,这个模块主要用于解决文件同步延迟问题,通过将请求重定向到上传文件的storage服务器来实现。 配置步骤大致如下: 1. 确保已经安装了FastDFS,并且配置了tracker和storage。 2. 安装fastdfs-nginx-module模块。 3. 修改fastdfs-nginx-module的配置文件(通常是mod_fastdfs.conf)以连接到FastDFS。 4. 重新配置Nginx,在配置文件中添加fastdfs-nginx-module的配置。 具体步骤: 步骤1:安装fastdfs-nginx-module 如果没有安装,需要下载并解压fastdfs-nginx-module,然后进入Nginx的源码目录,重新配置Nginx,添加该模块,再编译安装。 步骤2:配置mod_fastdfs.conf 通常,该文件位于/etc/fdfs目录下(可能需要从源码目录的conf中复制过来)。需要修改以下关键参数: - tracker_server:指定tracker服务器的地址和端口。 - url_have_group_name:设置为true,因为URL中包含组名。 - store_path0:指定存储路径,与storage.conf中的一致。 步骤3:配置NginxNginx的配置文件中(例如:nginx.conf),添加一个server块来处理FastDFS文件的请求。例如: ```nginx server { listen 80; server_name localhost; location ~ /group[0-9]/M00 { # 这里使用ngx_fastdfs_module模块 ngx_fastdfs_module; } # 其他配置... } ``` 注意:location的路径模式(~ /group[0-9]/M00)需要匹配FastDFS存储的文件路径。其中,M00对应存储路径的符号链接。 步骤4:启动Nginx 启动前确保已经启动了tracker和storage服务。然后启动Nginx。 注意:在重新配置Nginx时,如果之前已经安装了Nginx,需要重新编译Nginx,添加fastdfs-nginx-module模块。具体编译命令如下(在Nginx源码目录下执行): ./configure --add-module=/path/to/fastdfs-nginx-module/src make make install 如果已经安装过Nginx,不想覆盖原有安装,可以只替换nginx二进制文件(注意备份),或者使用新目录安装。 根据引用[2]中的例子,启动Nginx的命令可能是:`/usr/local/nginx/sbin/nginx` 另外,引用[3]中提到,这个模块的作用是解决同步延迟问题,因此配置正确后,当文件还未同步到其他storage时,客户端请求会被重定向到上传的storage服务器。 请确保在配置过程中,mod_fastdfs.conf中的tracker_server设置正确,并且storage.conf和mod_fastdfs.conf中的store_path设置一致。 如果遇到权限问题,确保Nginx用户(通常是nobody或www-data)有权限访问storage的存储路径。 以上步骤是配置Nginx使用fastdfs-nginx-module模块的基本流程。</think>### 配置 Nginx 使用 fastdfs-nginx-module 模块 以下是完整的配置步骤(基于 FastDFS v6.x 和 Nginx): #### 1. **安装依赖和模块** ```bash # 安装 FastDFS 基础库 wget https://github.com/happyfish100/libfastcommon/archive/V1.0.43.tar.gz tar -zxvf V1.0.43.tar.gz cd libfastcommon-1.0.43/ ./make.sh && ./make.sh install # 安装 fastdfs-nginx-module wget https://github.com/happyfish100/fastdfs-nginx-module/archive/V1.22.tar.gz tar -zxvf V1.22.tar.gz ``` #### 2. **配置 Nginx 编译参数** 重新编译 Nginx 添加模块: ```bash # 进入 Nginx 源码目录 ./configure \ --add-module=/path/to/fastdfs-nginx-module-1.22/src \ --with-http_stub_status_module \ --with-http_ssl_module make && make install ``` #### 3. **关键配置文件** **(1) 修改 `mod_fastdfs.conf`**(通常位于 `/etc/fdfs/`) ```ini # 连接 tracker 服务器 tracker_server=192.168.1.100:22122 # 替换为实际IP # 存储路径(与 storage.conf 一致) store_path0=/data/fastdfs/storage # 允许 URL 包含组名 url_have_group_name=true ``` **(2) Nginx 配置示例**(`nginx.conf` 中添加) ```nginx server { listen 80; server_name fastdfs.example.com; location ~ /group[1-9]/M00 { # 核心配置:指向模块 ngx_fastdfs_module; # 解决跨域问题(可选) add_header Access-Control-Allow-Origin *; add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS'; } # 错误日志 error_log /var/log/nginx/fastdfs_error.log; } ``` #### 4. **创建符号链接** ```bash # 将存储目录链接到 HTTP 路径 ln -s /data/fastdfs/storage/data /data/fastdfs/storage/data/M00 ``` #### 5. **启动服务** ```bash # 启动 FastDFS /etc/init.d/fdfs_trackerd start /etc/init.d/fdfs_storaged start # 启动 Nginx /usr/local/nginx/sbin/nginx ``` #### 6. **验证配置** 上传测试文件: ```bash fdfs_upload_file /etc/fdfs/client.conf test.jpg ``` 返回路径如:`group1/M00/00/00/test.jpg` 访问 URL:`http://fastdfs.example.com/group1/M00/00/00/test.jpg` ### 关键原理说明 - **文件路由机制**:当客户端请求文件时,Nginx 通过 `fastdfs-nginx-module` 直接定位到上传文件的 storage 节点,避免同步延迟导致的文件缺失问题[^3]。 - **组名支持**:`url_have_group_name=true` 使 URL 支持 `group1/M00/...` 格式,这是 FastDFS 的标准路径结构[^1]。 - **存储一致性**:`store_path0` 必须与 storage 服务器的配置完全一致,否则会导致文件查找失败[^2]。 --- ### 常见问题解决 1. **报错 `file not found`** - 检查 `mod_fastdfs.conf` 与 `storage.conf` 的 `store_path` 是否一致 - 确认 M00 符号链接存在:`ls -l /data/fastdfs/storage/data` 2. **Nginx 无法加载模块** 重新编译时确认模块路径: ```bash nginx -V 2>&1 | grep fastdfs-nginx-module ``` 3. **跨域访问问题** 在 Nginx 配置中添加 `Access-Control-Allow-*` 头(参考步骤3的示例)。 ---
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值