Nginx文件服务器搭建

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即可

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值