CENTOS 7下发布文件夹和静态文件如JPG等

CENTOS 7下 用Nginx发布文件夹和静态文件如JPG等

    • 一、尝试用Apache发布(后来证明不可行)
      • 1. apache的conf文档位于`/etc/httpd/conf/`目录下,编辑该文档:
      • 2. 打开网页localhost:8013【8013端口是我分配给apache的】
    • 二、尝试使用Nginx发布

一、尝试用Apache发布(后来证明不可行)

1. apache的conf文档位于/etc/httpd/conf/目录下,编辑该文档:

  1. root权限下 vi之:[root@localhost httpd]# vi /etc/httpd/conf/httpd.conf

  2. 输入i进入INSERT编辑状态

  3. 修改其中的语句DocumentRoot "/var/www/html"的路径到自己想要的路径之下DocumentRoot "/home/ruxianliuying/Storage"

  4. ESC退出编辑模式,输入:wq保存并退出。

  5. 重启apache:[root@localhost httpd]# systemctl restart httpd.service

2. 打开网页localhost:8013【8013端口是我分配给apache的】

>>>>>>ERROR来啦:巨大的Forbidden

Forbidden
You don’t have permission to access / on this server.

查询了网页上的各种解决策略,综合如下:

  1. 继续编辑apache的httpd.conf文档:在Directory的位置注销掉之前的代码,更换新的代码:

@注销掉的代码:

#
#    AllowOverride none
#    Require all denied
#

@更换成新的代码行:

表示开放所有访问


    Options Indexes FollowSymLinks
    AllowOverride all
    Require all granted


然并卵,依然Forbidden。。。

猜测可能是文件夹策略问题,因此先查看一下文件夹权限:没问题…决定放弃之,选择Nginx:

二、尝试使用Nginx发布

1. 安装和配置Nginx
参考文档:
https://blog.csdn.net/z564005425/article/details/81218929?utm_source=blogxgwz2
按照该文档的步骤:
(1)安装:yum install -y nginx
(2)设置配置文件:vi /etc/nginx/nginx.conf,在其中设置server的内容,具体请看参考文档。文档中是直接链接到某一个html或者jsp的,我想要对应至某一个文件夹,并获得其子文件夹内的JPG图片文件。经过多方参考,我的设置如下:

				server {    
					        listen       8015;    
					        server_name  localhost;    
					        location /Storage {  
									root /usr/local/images;
									autoindex on;
					                autoindex_exact_size off;
					                autoindex_localtime on;
					        }

最终定位的网页位置为:http://localhost:8015/Storage/A1/2018/10/1.JPG
(3)在防火墙中添加该IP端口允许:

1.2.1: /sbin/iptables -I INPUT -p tcp --dport 8015 -j ACCEPT;
	1.2.2: service iptables save;
	1.2.3: semanage port -a -t http_port_t -p tcp 8015
	1.2.4: systemctl restart iptables.service

(4)启动nginx:
报错:无法启动nginx!!!参考简书中的一篇文章检查:
检查启动状态:systemctl status nginx.service
!!!原来是IP端口被占用了
检查端口占用:
所有端口情况:netstat -tunlp,单个端口检查方法:lsof -i:80netstat -tunlp |grep 8080
!!!被apache占用了
解决方案:修改nginx的默认端口,设置文件位于/etc/nginx/conf.d/default.conf
a. vi /etc/nginx/conf.d/default.conf
b. 修改server listen: from 80 to 8014,如下,仅修改listen
c. 添加该IP端口允许,具体步骤如上。
d. 转到/etc/nginx下启动nginx:systemctl start nginx

			````
				# default.conf:
				server {
				    listen       8014;
				    server_name  localhost;
				
				    #charset koi8-r;
				    #access_log  /var/log/nginx/host.access.log  main;
				
				    location / {
				        root   /usr/share/nginx/html;
				        index  index.html index.htm;
				    }
				````
  1. 设置好了,启动nginx:systemctl start nginx,启动OK!针对8014端口也出现了欢迎页,但是8015端口对应的文件夹链接却显示Permission Deny
  2. 原来是我的对应文件夹开始设置到了/home/ruxianliuying/images/之下,二者不属于同一个账户,无法连接,因此将我的文件夹cp/usr/local/images下,输入连接http://localhost:8015/Storage/A1/2018/10/1.JPGOK!!
  3. 切记:用copy命令cp,不要用move命令mv,因为权限问题,有时候无法做好设置,mv之后文件夹的权限依然是旧的状态,我使用了chmod,chown等各种方法做了权限设置,都不行,所以,还是老老实实copy比较好。当然,哪位大神可否指点一下为什么我用权限设置设置了755权限也会报403 forbidden的原因。。。

你可能感兴趣的:(Linux,apache,Nginx,PostgreSQL,Mono+jexus,Nginx,Linux)