Linux下使用nginx搭建文件服务器
安装nginx
1、安装依赖
[root@nginx ~]# yum install -y gcc pcre-devel zlib-devel openssl openssl-devel
2、下载nginx
### 二进制包方式
[root@nginx ~]# mkdir -p /www/nginx
[root@nginx ~]# cd /www/nginx
[root@nginx ~]# wget http://nginx.org/download/nginx-1.21.0.tar.gz
[root@nginx ~]# tar -xvf nginx-1.21.0.tar.gz
### yum源安装
[root@nginx ~]# yum install -y wget
[root@nginx ~]# curl -o /etc/yum.repos.d/epel-7.repo https://mirrors.aliyun.com/repo/epel-7.repo
[root@nginx ~]# yum install -y nginx
[root@nginx ~]# yum info nginx
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.cqu.edu.cn
* extras: mirrors.cqu.edu.cn
* updates: mirrors.cqu.edu.cn
Installed Packages
Name : nginx
Arch : x86_64
Epoch : 1
Version : 1.20.1
Release : 10.el7
Size : 1.7 M
Repo : installed
From repo : epel
Summary : A high performance web server and reverse proxy server
URL : https://nginx.org
License : BSD
Description : Nginx is a web server and a reverse proxy server for HTTP, SMTP, POP3 and
: IMAP protocols, with a strong focus on high concurrency, performance and low
: memory usage.
3、安装nginx
[root@nginx ~]# cd nginx-1.21.0
先看 /usr/local/nginx 目录是否存在,不存在就创建:
[root@nginx ~]# mkdir -p /usr/local/nginx
指定安装路径:
[root@nginx ~]# ./configure --prefix=/usr/local/nginx
[root@nginx ~]# make && make install
4、修改配置文件
打开配置文件
[root@nginx ~]# vi /usr/local/nginx/conf/nginx.conf
5、启动nginx
[root@nginx ~]# cd /usr/local/nginx/sbin/
[root@nginx ~]# ./nginx
6、修改配置文件
### 二进制
[root@nginx ~]# mkdir -p /home/download
[root@nginx ~]# vi /usr/local/nginx/conf/nginx.conf
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
#root html;
root /home/download/;
autoindex on; ### 显示目录
autoindex_exact_size on; ### 显示文件大小
autoindex_localtime on; ### 显示文件时间
index index.html index.htm;
}
### yum源
[root@nginx ~]# vi /etc/nginx/nginx.conf
server {
listen 80;
listen [::]:80;
server_name localhost;
location / {
#root /usr/share/nginx/html;
root /home/download;
autoindex on; ### 显示目录
autoindex_exact_size on; ### 显示文件大小
autoindex_localtime on; ### 显示文件时间
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
}
error_page 404 /404.html;
location = /404.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
7、重启nginx
[root@nginx ~]# cd /usr/local/nginx/sbin/
[root@nginx ~]# ./nginx -s reload
如果要指定端口,修改linsten后面的监听端口80即可