zoukankan      html  css  js  c++  java
  • linux上搭建nginx+ftp,实现文件的上传与访问

     ftp服务器搭建

    1、新建用户ftpuser并指定主目录为/home/ftpuser

    (注意:这个目录是后面存储和读取文件的目录)

    <!--创建用户并指定主目录-->
    useradd -d /home/ftpuser  -m ftpuser  
    <!--修改密码为:Zxit@2018-->
    passwd  ftpuser  
    Zxit@2018
    <!--查看-->
    cat /etc/passwd

    2、ftp安装

    <!--查看是否安装ftp-->
     rpm -qa |grep vsftpd
    <!--没有则进行安装-->
    yum install -y vsftpd

    3、配置

    注:1、ftp默认的安装目录为/etc/vsftpd/

            2、添加内容:蓝色部分表示修改,黄色部分表添加

    <!--进入配置文件编辑模式-->
    vim /etc/vsftpd/vsftpd.conf
    <!--配置如下-->
    # 允许匿名用户访问:公网,为了安全选择关闭
    anonymous_enable=NO
    # 被动模式:公网,为了安全开启被动模式
    connect_from_port_20=NO

    pasv_enable=YES
    pasv_min_port=24322
    pasv_max_port=24325
    pasv_address=**.**.**.243
    
    # 让vsftpd同时支持IPv4和IPv6
    listen_ipv6=YES
    pam_service_name=vsftpd
    # 只允许名单内用户登录userlist_enable=YES
    # 限制用户的ip地址登录
    tcp_wrappers=YES
    #指定文件存储位置:即上面创建用户时指定的主目录local_root=/home/ftpuser
    allow_writeable_chroot=YES
    #修改端口:默认端口是21
    listen_port=24321

     

    4、启动ftp

    <!--启动-->
    systemctl start vsftpd.service
    <!--查看状态-->
    systemctl status vsftpd.service
    <!--查看进程-->
    ps -ef | grep ftp

     

    nginx安装

    1、用脚本自动安装nginx

    <!--新建auto_install_nginx.sh-->
    
    <!--写入以下内容-->
    
    #!/bin/bash
    ##2019 03 12 15:45:55
    ###设置相关参数
    NGINX_URL=http://nginx.org/download/nginx-1.14.2.tar.gz
    #NGINX_YL=gcc openssl openssl-devel zlib zlib-devel gcc-c++ pcre pcre-devel libgcc
    NGINX_HOME=/usr/local/nginx
    ###下载安装包###
    wget $NGINX_URL
    ###安装相关依赖包###
    yum install -y gcc openssl openssl-devel zlib zlib-devel gcc-c++ pcre pcre-devel libgcc
    ###解压并进入到相关目录###
    tar -xzf nginx-1.14.2.tar.gz
    cd nginx-1.14.2/
    ###预编译###
    ./configure --prefix=$NGINX_HOME --with-http_stub_status_module --with-http_ssl_module
    ###编译###
    make
    ###安装###
    make install
    ###启动###
    $NGINX_HOME/sbin/nginx
    ###关闭防火墙###
    service firewalld stop
    ###查看进程###
    ps -ef | grep nginx
    ###查看端口
    netstat -ntlp | grep 80
    
    
    <!--执行并安装nginx-->
    auto_install_nginx.sh

    2、启动ftp的nginx

    <!--进入nginx配置文件目录-->
    cd /usr/local/nginx/conf/
    <!--复制配置文件-->
     cp  nginx.conf nginx_ftp.conf
        
    <!--进入nginx配置文件目录-->
    cd /usr/local/nginx/conf/
    <!--复制配置文件-->
     cp  nginx.conf nginx_ftp.conf
    <!--进入配置文件编辑模式-->
    vim nginx_ftp.conf
    <!--配置如下-->
        server {
            listen 24388;
            server_name 127.0.0.1;
            location / {
                root /home/ftpuser;
            }
            error_page 500 502 503 504 /50x.html;
            location = /50x.html {
                root html;
            }
        }
    <!--启动-->
    /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx_ftp.conf
    <!--查看进程-->
    ps -ef | grep nginx
                        

    开放端口

    将刚刚配置的端口24321-24325(ftp)、24388(nginx_ftp)开放出来。注意:如果有firewalld之类的防火墙,也要注意开放端口。为了方便,我这里直接将防火墙关闭了。

    上传文件测试

    1、找一台能连ftp服务器的电脑,连接ftp并上传文件

    <!--连接ftp服务器-->
    ftp
    open **.**.**.243 24321
    ftpuser
    Zxit@2018
    <!--上传文件-->
    put C:UsersadminDownloadsgl_android.png

    2、解决报错:

    500 Illegal PORT command.
    425 Use PORT or PASV first.

    <!--是因为刚刚在ftp配置文件中,我配置的是被动模式,所以这里需要切换为被动模式-->
    LITERAL PASV
    <!--再次测试上传-->
    put C:UsersadminDownloadsgl_android.png

    3、查看文件是否上传成功

    <!--进入主目录-->
    cd /home/ftpuser/
    <!--查看-->
    ll

    这里看到文件已经成功上传上来了。

    访问文件测试

    用nginx转发访问刚刚上传的文件,访问路径:ip+nginx_ftp端口+文件目录+文件名(注意:刚刚在nginx上配置的路径 下面的所有文件可以直接访问)

     

  • 相关阅读:
    左偏树
    论在Windows下远程连接Ubuntu
    ZOJ 3711 Give Me Your Hand
    SGU 495. Kids and Prizes
    POJ 2151 Check the difficulty of problems
    CodeForces 148D. Bag of mice
    HDU 3631 Shortest Path
    HDU 1869 六度分离
    HDU 2544 最短路
    HDU 3584 Cube
  • 原文地址:https://www.cnblogs.com/yybrhr/p/11417607.html
Copyright © 2011-2022 走看看