将nginx.conf里的server--location--root 由默认的html改为/home/ftpuser/www后,要怎样做,才能访问到ftp上的图片

这是我在做图片服务器搭建的过程中遇到的问题:

1、前提条件:nginx和ftp的安装都是OK的。

1.1 按照nginx安装手册安装完nginx后,正常情况下,访问nginx首页是可以的。

将nginx.conf里的server--location--root 由默认的html改为/home/ftpuser/www后,要怎样做,才能访问到ftp上的图片

1.2ftp服务器按照vsftpd安装手册安装完成后,用FileZilla客户端也是可以连上的。

将nginx.conf里的server--location--root 由默认的html改为/home/ftpuser/www后,要怎样做,才能访问到ftp上的图片

2、问题出现和解决的过程:

因为我现在想使用http的方式访问图片服务器上的图片,所以(2.1)将nginx安装目录(即/usr/local/nginx)下的nginx.conf配置文件做了如下修改:

将nginx.conf里的server--location--root 由默认的html改为/home/ftpuser/www后,要怎样做,才能访问到ftp上的图片

这时访问nginx首页报403 Forbidden也是正常的,因为它的root让我改了嘛。

这时访问ftp服务器上的图片,报404 not found 错误。

将nginx.conf里的server--location--root 由默认的html改为/home/ftpuser/www后,要怎样做,才能访问到ftp上的图片

这时需要做以下几件事,就可以访问到ftp服务器上的图片了:

(2.2)将nginx.config的user我的默认是注释掉的,打开改为和启动用户一致。如果将root改成nobody还是会报403。

将nginx.conf里的server--location--root 由默认的html改为/home/ftpuser/www后,要怎样做,才能访问到ftp上的图片

这时重新启动nginx会报错:

将nginx.conf里的server--location--root 由默认的html改为/home/ftpuser/www后,要怎样做,才能访问到ftp上的图片

解决办法是:(2.3)创建“/var/run/nginx/nginx.pid”这样一个目录结构,因为我的只是nginx.pid文件没有,所以我只创建这个文件就可以了。

将nginx.conf里的server--location--root 由默认的html改为/home/ftpuser/www后,要怎样做,才能访问到ftp上的图片

这时再重新启动nginx或者关闭nginx命令时都会报错:

将nginx.conf里的server--location--root 由默认的html改为/home/ftpuser/www后,要怎样做,才能访问到ftp上的图片

解决办法是:(2.4)直接kill掉nginx里面的进程,然后重启nginx。

将nginx.conf里的server--location--root 由默认的html改为/home/ftpuser/www后,要怎样做,才能访问到ftp上的图片

将nginx.conf里的server--location--root 由默认的html改为/home/ftpuser/www后,要怎样做,才能访问到ftp上的图片

(2.5)这时,再访问ftp服务器上的图片就成功了。

将nginx.conf里的server--location--root 由默认的html改为/home/ftpuser/www后,要怎样做,才能访问到ftp上的图片

 

在解决这个问题的过程中参考的资料:

https://blog.****.net/onlysunnyboy/article/details/75270533

https://blog.****.net/z_cc_****/article/details/78122282

https://blog.****.net/PT1993/article/details/88997755