nginx配置檔案伺服器——帶說明
需求:
搭建一個檔案伺服器,提供指定軟體下載,在訪問檔案伺服器下載軟體時,在訪問的主頁上要有對應的軟體使用、安裝等說明(本來是可以搞一個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">由於當前公司的網路環境出現大量挖礦病毒。
為清除公司內網的威脅情況,請各位同事安裝公司指定的防病毒軟體。</h2>
<p align="center">防病毒軟體下載請訪問<a href="http://ip:埠">Download</a></p>
</div>
</body>
</html>
頁面如下:
這個html頁面根據需求來寫,主要注意,其中 <a href="http://IP:埠">Download</a>,這個配置顯示在頁面就是一個跳轉的連結,一定要注意帶http這個協議,不然跳轉不過去。
點選頁面中的Download跳轉後的頁面: