Linux配置nginx图片服务器+ftp服务器

1 篇文章 0 订阅
1 篇文章 0 订阅
 由于要实现图片上传,且服务器都要用阿里云的,Jboss也在Linux系统上,就采用了Nginx和FTP(也可采用nginx+NFS)。

        本篇博客主要介绍搭建Nginx和FTP的基本过程,部分简单且过细步骤从略,众亲自行百度即可。

        1、搭建Nginx

       (1)下载安装包,安装,Linux下安装nginx,需要先安装Gcc编译器、PCRE库、zlib库、OpenSSL开发库。然后再安装nginx。我用的Nginx-1.7.4版本,具体安装过程百度一下吧~

       (2)启动命令:/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf。 /usr/local/nginx/sbin/nginx是你nginx的安装目录;nginx.conf是配置文件。

         注意:要确定系统的80端口是否被占用,如果被占用,可用vi命令修改nginx.conf,具体修改方法见下面的配置文件。

 

     检查是否启动成功:ps -ef | grep nginx。

     如果成功了,看看在浏览器中输入http://127.0.0.1 是否访问到了Nginx欢迎界面?访问到就恭喜你安装成功了!


    (3)下面是如何配置nginx.conf,使其成为图片服务器。

     

  1. user  root;  
  2. worker_processes  1;  
  3. worker_rlimit_nofile 65535;  
  4.   
  5. #error_log  logs/error.log;  
  6. #error_log  logs/error.log  notice;  
  7. #error_log  logs/error.log  info;  
  8.   
  9. #pid        logs/nginx.pid;  
  10.   
  11.   
  12. events {  
  13.     worker_connections  12040;  
  14. }  
  15.   
  16.   
  17. http {  
  18.     include       mime.types;  
  19.     default_type  application/octet-stream;  
  20.     #Proxy_cache_path    /usr/local/nginx/NginxTestImgLog levels=1:2  keys_zone=cache_one:200m inactive=1d max_size=30g;  
  21.   
  22.     #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '  
  23.     #                  '$status $body_bytes_sent "$http_referer" '  
  24.     #                  '"$http_user_agent" "$http_x_forwarded_for"';  
  25.   
  26.     #access_log  logs/access.log  main;  
  27.   
  28.     sendfile        on;  
  29.     #tcp_nopush     on;  
  30.   
  31.     #keepalive_timeout  0;  
  32.     keepalive_timeout  65;  
  33.   
  34.     #gzip  on;  
  35.   
  36.     server {  
  37.         listen       8088;  
  38.         server_name  localhost;  
  39.   
  40.         #charset koi8-r;  
  41.   
  42.         #access_log  logs/host.access.log  main;  
  43.   
  44.         location / {  
  45.             root   html;  
  46.             index  index.html index.htm;  
  47.             #proxy_pass http://192.168.10.223:1234;  
  48.         }  
  49.   
  50.         #error_page  404              /404.html;  
  51.   
  52.         # redirect server error pages to the static page /50x.html  
  53.         #  
  54.         error_page   500 502 503 504  /50x.html;  
  55.         location = /50x.html {  
  56.             root   html;  
  57.         }  
  58.   
  59.         # proxy the PHP scripts to Apache listening on 127.0.0.1:80  
  60.         #  
  61.         #location ~ \.php$ {  
  62.         #    proxy_pass   http://127.0.0.1;  
  63.         #}  
  64.   
  65.         # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000  
  66.         #  
  67.         #location ~ \.php$ {  
  68.         #    root           html;  
  69.         #    fastcgi_pass   127.0.0.1:9000;  
  70.         #    fastcgi_index  index.php;  
  71.         #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;  
  72.         #    include        fastcgi_params;  
  73.         #}  
  74.   
  75.         # deny access to .htaccess files, if Apache's document root  
  76.         # concurs with nginx's one  
  77.         #  
  78.         #location ~ /\.ht {  
  79.         #    deny  all;  
  80.         #}  
  81.     }  
  82.   
  83.   
  84.     # another virtual host using mix of IP-, name-, and port-based configuration  
  85.     #  
  86.     #server {  
  87.     #    listen       8000;  
  88.     #    listen       somename:8080;  
  89.     #    server_name  somename  alias  another.alias;  
  90.   
  91.     #    location / {  
  92.     #        root   html;  
  93.     #        index  index.html index.htm;  
  94.     #    }  
  95.     #}  
  96.   
  97.   
  98.     # HTTPS server  
  99.     #  
  100. server {  
  101.         listen       7788;  
  102.         server_name  localhost;  
  103.     #    ssl on;  
  104.     #    ssl_certificate      /usr/local/nginx/conf/server.crt;  
  105.     #    ssl_certificate_key  /usr/local/nginx/conf/server_nopwd.key;  
  106.   
  107.     charset utf-8;  
  108.     #charset koi8-r;  
  109.       
  110.     location ~ (\.jsp)|(\.do)/ {  
  111.         proxy_pass http://127.0.0.1:7001;  
  112.         proxy_set_header X-Real-IP $remote_addr;  
  113.           
  114.         proxy_set_header Host $host;  
  115.         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;  
  116.         proxy_buffer_size 4k;  
  117.         proxy_buffers 4 32k;  
  118.         proxy_busy_buffers_size 64k;  
  119.         proxy_temp_file_write_size 64k;  
  120.         proxy_max_temp_file_size 512m;  
  121.       }  
  122.     }  
  123.       
  124.     server {  
  125.             listen 8888;  
  126.             server_name localhost;  
  127.           
  128.         charset utf-8;  
  129.           
  130.             location ~ .*\.(gif|jpg|jpeg|png){  
  131.                 #allow 127.0.0.1;  
  132.                 #deny all;  
  133.                   
  134.                 #expires 24h;  
  135.                     root /usr/local/nginx/nginxTestImg/;  
  136.                     access_log /usr/local/nginx/NginxTestImgLog/log_test.log;  
  137.                     proxy_store on;  
  138.                     proxy_store_access user:rw group:rw all:rw;  
  139.                       
  140.                     proxy_redirect    off;  
  141.                       
  142.                     proxy_set_header  Host $host;  
  143.                     proxy_set_header  X-Real-IP $remote_addr;  
  144.                     proxy_set_header  X-Forwarded-For $remote_addr;  
  145.                     client_max_body_size       10m;  
  146.                     client_body_buffer_size    1280k;  
  147.                     proxy_connect_timeout      900;  
  148.                     proxy_send_timeout         900;  
  149.                     proxy_read_timeout         900;  
  150.                     proxy_buffer_size          1024k;  
  151.                     proxy_buffers              40 1024k;  
  152.                     proxy_busy_buffers_size    1024k;  
  153.                     proxy_temp_file_write_size 1024k;  
  154.                 proxy_temp_path    /usr/local/nginx/nginxTestImg/;  
  155.                 #Proxy_cache_path /nginxTestImg/;  
  156.                 if ( !-e $request_filename)  
  157.                     {  
  158.                 proxy_pass http://127.0.0.1:8888;  
  159.                     }  
  160.                       
  161.             }  
  162.             location / {  
  163.                 root html;  
  164.                 index index.html index.htm;  
  165.             }  
  166.               
  167.             #error_page 404   /404.html;  
  168.             # redirect server error pages to the static page /50x.html  
  169.             #  
  170.             error_page   500 502 503 504  /50x.html;  
  171.             location = /50x.html {  
  172.                 root   html;  
  173.             }  
  174.               
  175.           
  176.     }  
  177.   
  178. }  

       

          配置完后,执行reload命令重新加载配置文件。然后放入一张图片(如,cat.jpg)后进行访问http://127.0.0.1:8888/cat.jpg ,如果能访问,说明搭建成功。



         2、搭建FTP服务器

       (1)安装,使用yum命令在Linux上安装即可

       (2)启动ftp服务 cd /ect/vsftpd(ftp的安装目录)   换行,./vsftpd.conf 或者service vsftpd restart(通用)

       (3)之后比较关键的是修改配置文件:

         首先,新建一个用户,如apple,并为其设置密码

  1. # useradd -d /etc/vsftpd/apple apple //增加用户apple,并制定test用户的主目录为/etc/vsftpd/apple  
  2. # passwd apple//为test设置密码  
            然后,把apple加到/etc/vsftpd/user_list文件中;如果该文件的同级文件vsftpd.chroot_list和ftpusers中含有你注册的用户名,要将其在这两个文件中注掉。

         重启ftp服务,命令见(2),就OK啦。

         还有一点要注意的是,如果使用ftp过程总是说无权限,要看看是否你的vsftpd里的文件有读写权限,设置属性即可。

         之后,在你的apple文件夹下放一个cat.jpg文件,在浏览器中输入http://xxx.xxx.xxx.xxx/8888/apple/cat.jpg,看看是否看到了你的图片?


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值