CentOS7 安装nginx 配置文件下载服务器

一.添加Nginx的repository

sudo yum install epel-release

二.安装Nginx

sudo yum install nginx

三.启动nginx

sudo systemctl start nginx
或者
service nginx start

四.验证

开放【80】端口

firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --reload

如果要关闭防火墙:

//临时关闭
systemctl stop firewalld

//禁止开机启动
systemctl disable firewalld

然后浏览器输入地址: http://ip 查看是否导航到默认页面

五.设置文件夹的目录

修改 config 文件

cd /etc/nginx
vi nginx.conf

在一个server{}中添加 一个location 部分

location / {
root /usr/share/myfiles/; # 这里配置目录
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
}

示例:

image.png

然后进入usr/share/目录,新建 myfiles 文件夹
重启nginx

sudo systemctl enable nginx

service nginx restart

六、验证

copy 一张图片到 server 的该共享目录下,可以使用 WinSCP 工具
浏览器输入地址,看到如下页面:


image.png

点击文件链接可查看该图片

你可能感兴趣的:(CentOS7 安装nginx 配置文件下载服务器)