[daily][centos][nginx] 在centos7使用nginx啟用對文件目錄的http訪問
阿新 • • 發佈:2017-10-13
mission lld 服務 nging 參考 索引 iss firewall bsp
1. 安裝nginx
yum install nginx
2. 修改配置
2.1 提供目錄權限:
我需要訪問的目錄是 /home/data, 用戶是data, 所以修改如下配置:
[[email protected] conf.d]# cat /etc/nginx/nginx.conf |grep user
user data;
否則會出現這樣的錯誤:
[[email protected] 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 所包含.
[[email protected] 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服務
[[email protected] conf.d]# systemctl enable nginx [[email protected] conf.d]# systemctl restart nginx
4. firewalld開啟nginx
參考: [daily][centos][iptables][firewalld] firewalld的初步了解
5. 修改配置, 增加8080端口:
[[email protected] conf.d]# cat /etc/firewalld/services/http.xml |grep 8080 <port protocol="tcp" port="8080"/> [[email protected] conf.d]#
[daily][centos][nginx] 在centos7使用nginx啟用對文件目錄的http訪問