nginx文件服务器搭建

时间:2019-07-04
本文章向大家介绍nginx文件服务器搭建,主要包括nginx文件服务器搭建使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

一.安装 (CentOS 7)

yum install nginx -y

如果报错:

[u3@L3 /]$ sudo yum install nginx -y

Loaded plugins: fastestmirror, langpacks

Loading mirror speeds from cached hostfile

 * base: mirrors.cn99.com

 * extras: mirrors.cn99.com

 * updates: mirrors.aliyun.com

No package nginx available.

Error: Nothing to do

先安装epel

yum install epel-release

二.启动

1、service nginx start

2、访问

 

三.文件目录配置

1vi /etc/nginx/nginx.conf

root配置:
        #root         /usr/share/nginx/html;

        root          /opt/package/;

Location / {}配置:

        location /package {

            autoindex on;

            autoindex_exact_size on;  # 显示文件大小

            autoindex_localtime on;  # 显示文件更新时间

            charset utf-8,gbk;

            add_header Content-Disposition attachment;  # 点击文件时下载

        }

2、nginx -s reload

(重新加载配置)

四.访问

/opt/package/package目录创建test.txt;

在浏览器中查看:

 

原文地址:https://www.cnblogs.com/penqiji/p/11134094.html