[daily][centos][nginx] 在centos7使用nginx启用对文件目录的http访问

 

1. 安装nginx

yum install nginx

2. 修改配置

2.1 提供目录权限:

  我需要访问的目录是 /home/data, 用户是data, 所以修改如下配置:

[root@S205 conf.d]# cat /etc/nginx/nginx.conf |grep user
user data;

否则会出现这样的错误:

[root@S205 conf.d]# tail /var/log/nginx/error.log 
2017/10/13 16:51:09 [error] 13383#0: *1 open() "/home/data" failed (13: Permission denied), client: 192.168.50.20, server: _, request: "GET /data HTTP/1.1", host: "192.168.10.205:8080"

2.2  创建新的配置, 在/etc/nginx/conf.d/目录下, 这个目录下的配置, 会被配置文件/etc/nginx/nginx.conf 所包含.

[root@S205 conf.d]# cat /etc/nginx/conf.d/data.conf 
server {
        listen       8080 default_server;
        server_name  data;
        root         /home/data;

        location / {
                autoindex on;
                autoindex_localtime on;
        }
}

2.3 autoindex 和 autoindex_localtime 是为了生成目录索引, 参考:

http://blog.licess.com/nginx-autoindex/

 

3.  启动ngingx服务

[root@S205 conf.d]# systemctl enable nginx
[root@S205 conf.d]# systemctl restart nginx

 

4.  firewalld开启nginx

参考:  [daily][centos][iptables][firewalld] firewalld的初步了解

5. 修改配置, 增加8080端口:

[root@S205 conf.d]# cat /etc/firewalld/services/http.xml |grep 8080
  <port protocol="tcp" port="8080"/>
[root@S205 conf.d]# 

 

posted on 2017-10-13 17:24  toong  阅读(535)  评论(0编辑  收藏  举报