Linux中用Nginx和FTP搭建WS幸运飞艇平台搭建图片服务器

一、需要的组件WS幸运飞艇平台搭建论坛:haozbbs.com Q1446595067

图片服务器两个服务:
Nginx(图片访问):

1、http服务:可以使用nginx做静态资源服务器。也可以使用apache。推荐使用nginx,效率更高。

2、反向代理 实现 负载均衡
ftp服务(图片上传):

使用linux做服务器,在linux中有个ftp组件vsftpd。
二、Nginx服务器搭建
1.安装Nginx

要求安装vmware虚拟机。

Linux:CentOS6.4(32)

Nginx:1.8.0

Vsftpd:需要在线安装。

虚拟机以及Linux安装很简单此处略。

Linux的局域网IP为:192.168.1.110

修改Linux的IP并立即生效的命令:
[java] view plain copy

#切换root管理员用户  
[root@localhost ~]# su  
password   
#设置本机IP并立即生效     
[root@localhost ~]# ifconfig eth0 192.168.1.110 netmask 255.255.255.0  

1.1、nginx安装环境

nginx是C语言开发,建议在linux上运行,本教程使用Centos6.5作为安装环境。

n gcc

     安装nginx需要先将官网下载的源码进行编译,编译依赖gcc环境,如果没有gcc环境,需要安装gcc:yum install gcc-c++

n PCRE

     PCRE(PerlCompatible Regular Expressions)是一个Perl库,包括 perl 兼容的正则表达式库。nginx的http模块使用pcre来解析正则表达式,所以需要在linux上安装pcre库。

[java] view plain copy

[root@localhost ~]#yum install -y pcre pcre-devel  

注:pcre-devel是使用pcre开发的一个二次开发库。nginx也需要此库。

n zlib

     zlib库提供了很多种压缩和解压缩的方式,nginx使用zlib对http包的内容进行gzip,所以需要在linux上安装zlib库。

[java] view plain copy

[root@localhost ~]#yum install -y zlib zlib-devel  

n openssl

     OpenSSL是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及SSL协议,并提供丰富的应用程序供测试或其它目的使用。

     nginx不仅支持http协议,还支持https(即在ssl协议上传输http),所以需要在linux安装openssl库。

[java] view plain copy

[root@localhost ~]#yum install -y openssl openssl-devel  

1.2、把nginx安装包nginx-1.8.0.tar.gz上传到服务器。

在secureCRT打开sftp会话框,上传文件

使用put/get命令 或者直接拖拽文件
1.3、解压缩(在安装包所在目录执行)

[java] view plain copy

[root@localhost ~]# tar -zxvf nginx-1.8.0.tar.gz  

在root@bogon nginx-1.8.0目录下

./configure && make && make install //在这里吃过亏

1.5、编译安装

编译:
[java] view plain copy

[root@localhost nginx-1.8.0]# make  

安装:

[java] view plain copy

[root@localhost nginx-1.8.0]# make  install  

安装成功以后进入安装目录(创建makedir时指定的”--prefix=/usr/local/nginx \“)

[java] view plain copy

[root@localhost nginx-1.8.0]# cd /usr/local/nginx/  

2、nginx运行
2.1、启动nginx

[java] view plain copy

[root@localhost nginx]# cd sbin  
[root@localhost sbin]# ./nginx  

2.2、关闭
[java] view plain copy

[root@localhost sbin]# ./nginx -s stop  

2.3、重新加载配置文件
[java] view plain copy

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

2.4、关闭防火墙
[java] view plain copy

[root@localhost ]# /sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT    
[root@localhost ]# /etc/init.d/iptables save    
[root@localhost ]# /etc/init.d/iptables restart   

2.5、访问nginx服务

顺便给新手推荐一个无意中发现的Java网站,感觉超级适合入门级的Java开发,

基础知识写的挺好,练手项目也很丰富很,基本都是文档形式指导,简明易懂,不像视频一样费时间。

地址是http://how2j.cn?p=24192

3、关于图片服务器配置

进入配置文件目录
[java] view plain copy

cd /usr/local/nginx/conf/  

nginx的默认配置文件nginx.config
[java] view plain copy

#user  nobody;  
worker_processes  1;  

#error_log  logs/error.log;  
#error_log  logs/error.log  notice;  
#error_log  logs/error.log  info;  

#pid        logs/nginx.pid;  

events {  
    worker_connections  1024;  
}  

http {  
    include       mime.types;  
    default_type  application/octet-stream;  

    #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       80;  
        server_name  localhost;  

        #charset koi8-r;  

        #access_log  logs/host.access.log  main;  

        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;  
        }  

        # 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       443 ssl;  
    #    server_name  localhost;  

    #    ssl_certificate      cert.pem;  
    #    ssl_certificate_key  cert.key;  

    #    ssl_session_cache    shared:SSL:1m;  
    #    ssl_session_timeout  5m;  

    #    ssl_ciphers  HIGH:!aNULL:!MD5;  
    #    ssl_prefer_server_ciphers  on;  

    #    location / {  
    #        root   html;  
    #        index  index.html index.htm;  
    #    }  
    #}  

}  

配置图片服务器

方法一、在配置文件server{}中location /{} 修改配置:
[java] view plain copy

 #默认请求  
location / {  
   root  /home/ftpuser/www;#定义服务器的默认网站根目录位置  
   index index.html index.php index.htm;#定义首页索引文件的名称  
}  

其中:/home/ftpuser/www;为创建FTP服务账户ftpuser的根目录下的www目录

方法二、在http{}内配置新服务
[java] view plain copy

server {  
        listen       8080;  
        server_name  localhost;  

        #charset utf-8;  

        #access_log  logs/host.access.log  main;  

        #默认请求  
        location / {  
            root  /home/ftpuser/www;#定义服务器的默认网站根目录位置  
            index index.html index.php index.htm;#定义首页索引文件的名称  
           }  
        }  

因为需要开始端口号8080,所以要在防火墙中开启8080端口
[java] view plain copy

[root@localhost ]# /sbin/iptables -I INPUT -p tcp --dport 8080 -j ACCEPT    
[root@localhost ]# /etc/init.d/iptables save    
[root@localhost ]# /etc/init.d/iptables restart   

三、FTP服务的安装与启动
1、安装vsftpd组件

vsftpd组件为Linux的FTP服务组件,安装方式为在线安装。

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

安装完后,有/etc/vsftpd/vsftpd.conf 文件,是vsftp的配置文件。
2、添加一个ftp用户

此用户就是用来登录ftp服务器用的。
[java] view plain copy

[root@localhost ~]# useradd ftpuser  

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

为这个ftp账户添加密码

猜你喜欢

转载自blog.51cto.com/13856950/2137505
今日推荐