1。安装nginx
默认源没有nginx,需添加nginx源
sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
sudo yum install -y nginx
sudo systemctl start nginx.service
sudo systemctl enable nginx.service
2。vi /etc/nginx/conf.d/default.conf
修改
charset utf-8;
修改location/处为如下
root后面的为指定的文件夹
location / {
# root /usr/share/nginx/html;
# index index.html index.htm;
root /home/vsftpd/;
autoindex on;
}
3。关闭selinux
vi /etc/sysconfig/selinux修改如下
SELINUX=disabled
4。curl 127.0.0.1测试
5。开防火墙端口
firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --reload
firewall-cmd --list-all
然后外网访问测试
6。限速设置
vi /etc/nginx/nginx.conf
include /etc/nginx/conf.d/*.conf;这一行前面添加
limit_conn_zone $binary_remote_addr zone=one:10m;
vi /etc/nginx/conf.d/default.conf,每ip限两个连接,每个连接限速1m,location/添加
limit_conn one 2;
limit_rate 1m;
service nginx restart
7。友好视图设置
vi /etc/nginx/conf.d/default.conf,location/添加
autoindex_exact_size off;
autoindex_localtime on;
8。设置访问验证
提供一个在线工具:http://tool.oschina.net/htpasswd 在这里输入用户名密码后选择Crypt加密算法。
vi /etc/nginx/passwd,添加上面生成的文本
vi /etc/nginx/conf.d/default.conf,location/添加
auth_basic "Authorized users only";
auth_basic_user_file /etc/nginx/passwd;
9。页面美化
https://phus.lu/autoindex.html下载autoindex.html文件放到上述根目录
vi /etc/nginx/conf.d/default.conf,location/添加
add_after_body /autoindex.html;
10。添加readme.md文件
readme.md文件会自动读取显示在页面下方
换行的语法为添加<br>