通过HTTP服务访问FTP服务器文件(配置nginx+ftp服务器)

本是古典 何须时尚 2022-05-22 06:50 715阅读 0赞

1.前提

  1. 已安装配置好nginx+ftp服务
  2. 参考:
  3. nginx服务安装:https://blog.csdn.net/qq\_37725650/article/details/80726496
  4. FTP服务安装:https://blog.csdn.net/qq\_37725650/article/details/80590061

2.配置Nginx 服务器

  1. 2.1进入nginx 配置文件目录:
  2. [root@localhost vsftpd]# cd /usr/local/nginx/conf/
  3. [root@localhost conf]# ls
  4. fastcgi.conf fastcgi_params.default mime.types nginx.conf.default uwsgi_params
  5. fastcgi.conf.default koi-utf mime.types.default scgi_params uwsgi_params.default
  6. fastcgi_params koi-win nginx.conf scgi_params.default win-utf
  7. 2.2 修改配置文件:有两种方式
  8. ①方式一:在配置文件server\{\}location /\{\} 修改配置
  9. 1 #默认请求
  10. 2 location / {
  11. 3 root /home/ftpuser/www;#定义服务器的默认网站根目录位置
  12. 4 index index.html index.php index.htm;#定义首页索引文件的名称
  13. 5 }
  14. ②方式二:在http\{\}内配置新服务
  15. server {
  16. listen 8080;
  17. server_name localhost;
  18. #charset utf-8;
  19. #access_log logs/host.access.log main;
  20. #默认请求
  21. location / {
  22. root /home/ftpuser/www;#定义服务器的默认网站根目录位置
  23. index index.html index.php index.htm;#定义首页索引文件的名称
  24. }
  25. }
  26. 部署验证:
  27. ![70][]
  28. 解决方案:
  29. 1.查看配置文件中路径是否配置成功:
  30. location / {
  31. root /home/ftpuser/www;
  32. index index.html index.htm;
  33. }






[root@localhost conf]# cd /home/ftpuser/www/
[root@localhost www]# pwd
/home/ftpuser/www

  1. 两个路径完全匹配,说明路径没有问题。

2.查看路径中是否存在文件:







[root@localhost www]# ls
index.html

存在文件,可以排除是文件问题。

3.排查权限问题:

  1. [root@localhost conf]# cat nginx.conf
  2. #user nobody;
  3. worker_processes 1;
  4. #error_log logs/error.log;
  5. #error_log logs/error.log notice;
  6. #error_log logs/error.log info;
  7. #pid logs/nginx.pid;
  8. events {
  9. worker_connections 1024;
  10. }
  11. http {
  12. include mime.types;
  13. default_type application/octet-stream;
  14. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  15. # '$status $body_bytes_sent "$http_referer" '
  16. # '"$http_user_agent" "$http_x_forwarded_for"';
  17. #access_log logs/access.log main;
  18. sendfile on;
  19. #tcp_nopush on;
  20. #keepalive_timeout 0;
  21. keepalive_timeout 65;
  22. #gzip on;
  23. server {
  24. listen 80;
  25. server_name localhost;
  26. #charset koi8-r;
  27. #access_log logs/host.access.log main;
  28. location / {
  29. root /home/ftpuser/www;
  30. index index.html index.htm;
  31. }
  32. #error_page 404 /404.html;
  33. # redirect server error pages to the static page /50x.html
  34. #
  35. error_page 500 502 503 504 /50x.html;
  36. location = /50x.html {
  37. root html;
  38. }
  39. # proxy the PHP scripts to Apache listening on 127.0.0.1:80
  40. #
  41. #location ~ \.php$ {
  42. # proxy_pass http://127.0.0.1;
  43. #}
  44. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  45. #
  46. #location ~ \.php$ {
  47. # root html;
  48. # fastcgi_pass 127.0.0.1:9000;
  49. # fastcgi_index index.php;
  50. # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
  51. # include fastcgi_params;
  52. #}
  53. # deny access to .htaccess files, if Apache's document root
  54. # concurs with nginx's one
  55. #
  56. #location ~ /\.ht {
  57. # deny all;
  58. #}
  59. }
  60. # another virtual host using mix of IP-, name-, and port-based configuration
  61. #
  62. #server {
  63. # listen 8000;
  64. # listen somename:8080;
  65. # server_name somename alias another.alias;
  66. # location / {
  67. # root html;
  68. # index index.html index.htm;
  69. # }
  70. #}
  71. # HTTPS server
  72. #
  73. #server {
  74. # listen 443 ssl;
  75. # server_name localhost;
  76. # ssl_certificate cert.pem;
  77. # ssl_certificate_key cert.key;
  78. # ssl_session_cache shared:SSL:1m;
  79. # ssl_session_timeout 5m;
  80. # ssl_ciphers HIGH:!aNULL:!MD5;
  81. # ssl_prefer_server_ciphers on;
  82. # location / {
  83. # root html;
  84. # index index.html index.htm;
  85. # }
  86. #}
  87. }

发现用户权限没有开启。我们添加需要的用户。







[root@localhost conf]# vim nginx.conf

#user nobody;
user root;

重新加载 nginx 配置:







[root@localhost conf]# cd ../sbin/
[root@localhost sbin]# ./nginx -s reload

再次部署验证
70 1

发表评论

表情:
评论列表 (有 0 条评论,715人围观)

还没有评论,来说两句吧...

相关阅读