FTP+Nginx图片服务器

来源:互联网 发布:linux cp文件夹 编辑:程序博客网 时间:2024/05/16 15:00

    1. 安装vsftpd组件

    (提示nginx的安装上篇文章已经说过,这里就不讲了直接ftp安装,然后整合两个)

    [root@bogon ~]# yum -y install vsftpd

    安装完后,有/etc/vsftpd/vsftpd.conf文件,是vsftp的配置文件。


     

    1. 添加一个ftp用户

    此用户就是用来登录ftp服务器用的。

    [root@bogon ~]# useradd -d/home/ftpuser/www ftpuser

    这样一个用户建完,可以用这个登录,记得用普通登录不要用匿名了。登录后默认的路径为 /home/ftpuser.   

      /home/ftpuser.这个路径很重要,要在nginx中配置,才能将ftpnginx结合

    如果不想用这个路径,新建用户的时候就要加上自己的路径如/home/ftpuser/www

    [root@bogon ~]# useradd -d/home/ftpuser/www ftpuser

    1. ftp用户添加密码。

    [root@bogon ~]# passwd ftpuser

    输入两次密码后修改密码。

     

     

    4

    配置nginx.conf,使其成为图片服务器。

    nginx.conf的默认路径是/usr/local/nginx/conf

    此处你搜索下有两处/home/ftpuser/www这个是上面提到的路径,还有一个是log的路径也要改,下面的路径是/usr/local/nginx/NginxTestImgLog/log_test.log;改成自己的,

         

    user  root;worker_processes  1;worker_rlimit_nofile 65535;#error_log  logs/error.log;#error_log  logs/error.log  notice;#error_log  logs/error.log  info;#pid        logs/nginx.pid;events {    worker_connections  12040;}http {    include       mime.types;    default_type  application/octet-stream;        #Proxy_cache_path    /home/ftpuser/www levels=1:2  keys_zone=cache_one:200m inactive=1d max_size=30g;#log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '    #                  '$status $body_bytes_sent "$http_referer" '    #                  '"$http_user_agent" "$http_x_forwarded_for"';#access_log  logs/access.log  main;sendfile        on;    #tcp_nopush     on;#keepalive_timeout  0;    keepalive_timeout  65;#gzip  on;server {        listen       8088;        server_name  localhost;#charset koi8-r;#access_log  logs/host.access.log  main;location / {            root   html;            index  index.html index.htm;                        #proxy_pass http://192.168.10.223:1234;        }#error_page  404              /404.html;# redirect server error pages to the static page /50x.html        #        error_page   500 502 503 504  /50x.html;        location = /50x.html {            root   html;        }# proxy the PHP scripts to Apache listening on 127.0.0.1:80        #        #location ~ \.php$ {        #    proxy_pass   http://127.0.0.1;        #}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000        #        #location ~ \.php$ {        #    root           html;        #    fastcgi_pass   127.0.0.1:9000;        #    fastcgi_index  index.php;        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;        #    include        fastcgi_params;        #}# deny access to .htaccess files, if Apache's document root        # concurs with nginx's one        #        #location ~ /\.ht {        #    deny  all;        #}    }# another virtual host using mix of IP-, name-, and port-based configuration    #    #server {    #    listen       8000;    #    listen       somename:8080;    #    server_name  somename  alias  another.alias;#    location / {    #        root   html;    #        index  index.html index.htm;    #    }    #}# HTTPS server    #server {        listen       7788;        server_name  localhost;        #    ssl on;    #    ssl_certificate      /usr/local/nginx/conf/server.crt;    #    ssl_certificate_key  /usr/local/nginx/conf/server_nopwd.key;charset utf-8;        #charset koi8-r;                location ~ (\.jsp)|(\.do)/ {                proxy_pass http://127.0.0.1:7001;                proxy_set_header X-Real-IP $remote_addr;                                proxy_set_header Host $host;                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;                proxy_buffer_size 4k;                proxy_buffers 4 32k;                proxy_busy_buffers_size 64k;                proxy_temp_file_write_size 64k;                proxy_max_temp_file_size 512m;      }    }                server {                        listen 8888;                        server_name localhost;                                charset utf-8;                                        location ~ .*\.(gif|jpg|jpeg|png){                                #allow 127.0.0.1;                                #deny all;                                                                #expires 24h;                                        root /home/ftpuser/www/;                                        access_log /usr/local/nginx/NginxTestImgLog/log_test.log;                                        proxy_store on;                                        proxy_store_access user:rw group:rw all:rw;                                                                                proxy_redirect    off;                                                                                proxy_set_header  Host $host;                                        proxy_set_header  X-Real-IP $remote_addr;                                        proxy_set_header  X-Forwarded-For $remote_addr;                                        client_max_body_size       10m;                                        client_body_buffer_size    1280k;                                        proxy_connect_timeout      900;                                        proxy_send_timeout         900;                                        proxy_read_timeout         900;                                        proxy_buffer_size          1024k;                                        proxy_buffers              40 1024k;                                        proxy_busy_buffers_size    1024k;                                        proxy_temp_file_write_size 1024k;                                proxy_temp_path    /usr/local/nginx/nginxTestImg/;                                #Proxy_cache_path /nginxTestImg/;                                if ( !-e $request_filename)                                        {                                proxy_pass http://127.0.0.1:8888;                                        }                                                                }                        location / {                                root html;                                index index.html index.htm;                        }                                                #error_page 404   /404.html;                        # redirect server error pages to the static page /50x.html                        #                        error_page   500 502 503 504  /50x.html;                        location = /50x.html {                                root   html;                        }                                                }}


     

    停止nginx

    cd /usr/local/nginx/sbin

    ./nginx -s quit

     

    启动nginx

    ./nginx -c /usr/local/nginx/conf/nginx.conf

     

     

    成功如图

     

     

    这里我用例一个ftp的工具给大家介绍下叫FileZilla

     


    总结:搞了好几天今天终于有成果了,下篇文章估计会实现用springmvc上传图片,呼呼加油吧!

    ——————————————chenchen——————————————

     


0 0
原创粉丝点击