我这里使用的是centos7系统
nginx源码包安装
Linux:nginx基础搭建(源码包)ops_request_misc=%257B%2522request%255Fid%2522%253A%2522169599062316800184149954%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=169599062316800184149954&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~rank_v31_ecpm-2-131445878-null-null.nonecase&utm_term=nginx&spm=1018.2226.3001.4450
nginx yum源安装
mkdir /etc/yum.repos.d/bak
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak/
wget -O /etc/yum.repos.d/CentOS-Base.repo http:///repo/Centos-7.repo
rpm -Uvh http:///packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
搭建文件服务器
mkdir /var/www/nginx
这个目录作为我们文件服务器根目录,把文件存入这个目录下即可
chown nginx:nginx /var/www/nginx/
现在nginx的配置文件在/etc/nginx/conf.d/default.conf下
使用rpm -ql nginx 可以看到nginx的文件所在位置
vim /etc/nginx/conf.d/default.conf
写入
server {
listen 80;
server_name localhost;
charset utf-8;
root /var/www/nginx;
location / {
charset utf-8;
autoindex on;
autoindex_format html;
autoindex_exact_size off;
autoindex_localtime on;
default_type application/octet-stream;
if ($request_filename ~* ^.*?\.(txt|doc|pdf|rar|gz|zip|docx|exe|xlsx|ppt|pptx)$){
add_header Content-Disposition: 'attachment;';
}
sendfile on;
sendfile_max_chunk 1m;
tcp_nopush on;
directio 5m;
directio_alignment 4096;
output_buffers 4 32k;
max_ranges 4096;
send_timeout 20s;
postpone_output 2048;
chunked_transfer_encoding on;
}
上面配置文件的意思如下
现在开启一下nginx
systemctl start ngixn
直接访问nginx服务器ip
直接访问是这样的现在我去里面mkdir创建一个文件夹
点进去是这样的
现在往tarro文件夹里放一个文件
点击即可下载