Admin

centos7安装nginx并启用浏览文件目录
2019年4月20日 22:35 73 0 1 1

目录

0. 安装源

  1. rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

1. 安装

  1. sudo yum install nginx

2. 启动

  1. sudo systemctl start nginx

3. 启用浏览文件目录

3.1 创建目录

  1. mkdir /root/www

3.2 修改配置文件

  1. vim /etc/nginx/nginx.conf

3.2.1 修改运行nginx用户

  1. # user nginx;
  2. user root;

3.2.2 启用目录

  1. location / {
  2. root /root/www;
  3. autoindex on;
  4. autoindex_exact_size off;
  5. autoindex_localtime on;
  6. }

3.3 重启nginx服务

  1. sudo systemctl restart nginx

3.4 测试

  1. mkdir /root/www/files
  2. echo "hello" > /root/www/files/hello.txt
  3. curl 127.0.0.1/files/hello.txt

4. 开机自动启动nginx服务

  1. sudo systemctl enable nginx

5. 防火墙开放80端口

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

6. 问题排查

6.1 上述操作后访问返回403

  1. 确认nginx运行身份具有目录读取权限
  2. 确认selinux已关闭: 参考 https://blog.csdn.net/xinluke/article/details/51925293
发布内容,请遵守相关法律法规。
评论