您的位置:首页 > 运维架构 > Nginx

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

2016-01-27 23:40 567 查看
         由于要实现图片上传,且服务器都要用阿里云的,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,使其成为图片服务器。
     
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    /usr/local/nginx/NginxTestImgLog 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 /usr/local/nginx/nginxTestImg/;
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;
}

}

}


       

          配置完后,执行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,并为其设置密码
# useradd -d /etc/vsftpd/apple apple //增加用户apple,并制定test用户的主目录为/etc/vsftpd/apple
# 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,看看是否看到了你的图片?
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: