需求:
搭建一个文件服务器,提供指定软件下载,在访问文件服务器下载软件时,在访问的主页上要有对应的软件使用、安装等说明(本来是可以搞一个readme的,但这个在文件服务器上要下载还要打开,还不如直接显示出来)。
环境搭建:
Linux最小安装系统+nginx
配置:
安装nginx
yum install epel-release -y #安装扩展yum源
yum install nginx -y #安装nginx
systemctl start nginx #启动
systemctl enable nginx #开机启动
主配置文件:
路径:/etc/nginx nginx.conf
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main \'$remote_addr - $remote_user [$time_local] "$request" \'
\'$status $body_bytes_sent "$http_referer" \'
\'"$http_user_agent" "$http_x_forwarded_for"\';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
server_tokens off;
include /etc/nginx/conf.d/*.conf;
}
配置虚拟主机:
路径:/etc/nginx/conf.d
配置默认站点(主要是用来显示说明等,修改默认的index.html页面即可):
default站点配置:
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;
charset utf-8;
location = /favicon.ico {
return 204;
access_log off;
log_not_found off;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
文件站点配置:
server {
listen 8123;
server_name _;
charset utf-8;
location / {
root /data;
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
charset utf-8;
log_not_found off;
}
}
配置默认站点的index.html页面:
配置文件路径:/usr/share/nginx/html
<html>
<head>
<style rel="stylesheet" type="text/css">
h1 {
margin:50px auto;
}
h2 {
text-indent:2em;
line-height:45px;
margin:20px auto;
width:850px;
}
</style>
</head>
<body>
<div id="content">
<h1 align="center">欢迎访问--文件服务器</h1>
<h2 align="center">由于XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX。
为XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX软件。</h2>
<p align="center">XXXXXXXXXX下载请访问<a href="http://ip:端口">Download</a></p>
</div>
</body>
</html>
页面如下:
这个html页面根据需求来写,主要注意,其中 <a href="http://IP:端口">Download</a>,这个配置显示在页面就是一个跳转的链接,一定要注意带http这个协议,不然跳转不过去。
点击页面中的Download跳转后的页面:
当前,是这个方法来实现的,不知道是不是还有其他的方法,如果配置中存在安全问题或配置参数不正确的情况,请指正,谢谢!!