配置Nginx
安装或升级依赖
[root@banana ~]# yum install -y make cmake gcc gcc-c++ pcre pcre-devel zlib zlib-devel unzip zip telnet vim
...
Installed:
cmake.x86_64 0:2.8.12.2-2.el7 gcc-c++.x86_64 0:4.8.5-39.el7
telnet.x86_64 1:0.17-65.el7_8
Dependency Installed:
libarchive.x86_64 0:3.1.2-14.el7_7 libstdc++-devel.x86_64 0:4.8.5-39.el7
Updated:
gcc.x86_64 0:4.8.5-39.el7 make.x86_64 1:3.82-24.el7
vim-enhanced.x86_64 2:7.4.629-6.el7
Dependency Updated:
cpp.x86_64 0:4.8.5-39.el7 libgcc.x86_64 0:4.8.5-39.el7
libgomp.x86_64 0:4.8.5-39.el7 libstdc++.x86_64 0:4.8.5-39.el7
vim-common.x86_64 2:7.4.629-6.el7
Complete!
下载Nginx和fastdfs-nginx-module
下载源:http://nginx.org/download/
下载5月26日最新版:http://nginx.org/download/nginx-1.19.0.tar.gz
[root@banana ~]# cd ~/download/
[root@banana download]# wget http://nginx.org/download/nginx-1.19.0.tar.gz
[root@banana download]# git clone https://github.com/happyfish100/fastdfs-nginx-module.git
解压文件和安装
[root@banana download]# cd nginx-1.19.0
[root@banana nginx-1.19.0]# ls
auto CHANGES.ru configure html man src
CHANGES conf contrib LICENSE README
# configure用于配置 /root/download/fastdfs-nginx-module/src/是我们git clone fastdfs-nginx-module.git的路径
[root@banana nginx-1.19.0]# ./configure --prefix=/usr/local/nginx --add-module=/root/download/fastdfs-nginx-module/src/
# 编译安装
[root@banana nginx-1.19.0]# make && make install
# 进入目录
[root@banana nginx-1.19.0]# cd ../fastdfs-nginx-module/src/
# 复制配置文件
[root@banana src]# cp mod_fastdfs.conf /etc/fdfs/mod_fastdfs.conf
# 创建一个目录储存日志
[root@banana src]# mkdir -p /home/python/fastdfs/log
# 编辑配置文件
[root@banana src]# vim /etc/fdfs/mod_fastdfs.conf
# 修改如下内容:
base_path=/home/python/fastdfs/log
tracker_server=172.31.88.233,47.45.205.156:22122
storage_server_port=23000
group_name=group1
url_have_group_name = true
store_path0=/home/python/fastdfs/storage_data # 和storage.conf的一致
group_count = 3 # 虽然只用了一个group1
# group settings for group #1
# since v1.14
# when support multi-group on this storage server, uncomment following section
[group1]
group_name=group1
storage_server_port=23000
store_path_count=1
store_path0=/home/python/fastdfs/storage_data
store_path1=/home/python/fastdfs/storage_data
# group settings for group #2
# since v1.14
# when support multi-group, uncomment following section as neccessary
[group2]
group_name=group2
storage_server_port=23000
store_path_count=1
store_path0=/home/python/fastdfs/storage_data
[group3]
group_name=group3
storage_server_port=23000
store_path_count=1
store_path0=/hom/python/fastdfs/storage_data
复制配置文件
[root@banana src]# cd ~/download/fastdfs/conf/
[root@banana conf]# ls
anti-steal.jpg client.conf http.conf mime.types storage.conf storage_ids.conf tracker.conf
[root@banana conf]# cp mime.types /etc/fdfs/
[root@banana conf]# cp http.conf /etc/fdfs/
创建软链接
[root@banana conf]# ln -s /home/python/fastdfs/storage_data/data/ /home/python/fastdfs/storage_data/M00
修改Nginx配置文件
[root@banana ~]# vim /usr/local/nginx/conf/nginx.conf
# 修改:
server {
listen 8888;
server_name localhost;
#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/python/fastdfs/storage_data/data;
ngx_fastdfs_module;
}
启动Nginx服务
[root@banana ~]# /usr/local/nginx/sbin/nginx
ngx_http_fastdfs_set pid=12558
[root@banana ~]# ps -aux | grep nginx
root 12505 0.0 0.5 151376 5092 pts/0 S+ 13:40 0:00 vim /usr/local/nginx/conf/nginx.conf
root 12559 0.0 0.0 28172 660 ? Ss 14:02 0:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody 12560 0.0 0.2 29016 2152 ? S 14:02 0:00 nginx: master process /usr/local/nginx/sbin/nginx
root 12562 0.0 0.0 112712 984 pts/1 R+ 14:02 0:00 grep --color=auto nginx
查看Nginx服务
[root@banana ~]# netstat -unltp | grep nginx
tcp 0 0 0.0.0.0:8888 0.0.0.0:* LISTEN 12559/nginx: master
直接访问服务
curl 127.0.0.1:8888
重启Nginx服务
[root@banana ~]# /usr/local/nginx/sbin/nginx -s reload