分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 技术分享

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

发布时间:2023-09-06 01:17责任编辑:蔡小小关键词:nginxhttp

1. 安装nginx

yum install nginx

2. 修改配置

2.1 提供目录权限:

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

[root@S205 conf.d]# cat /etc/nginx/nginx.conf |grep useruser 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]# 

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

原文地址:http://www.cnblogs.com/hugetong/p/7662214.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved