NGINX初试

    WIN764位系统,安装了cygwin64模拟linux的环境,安装了tengine被包装过的NGINX。

傻瓜式安装,见http://tengine.taobao.org/document_cn/install_cn.html

安装可能遇见问题:(该问题是在ubuntu中时遇到的。

解压后的目录运行./configure,这时会报出一个如下错误:

./configure: error: the HTTP rewrite module requires the PCRE library.

这是因为没有PCRE library的原因所致,通过下面的命令安装相关的lib即可解决。

sudo apt-get install libpcre3 libpcre3-dev

重新./configure,这里可能会出现如下错误:
./configure: error: the HTTP cache module requires md5 functions
from OpenSSL library.   You can either disable the module by using
–without-http-cache option, or install the OpenSSL library into the system,
or build the OpenSSL library statically from the source with nginx by using
–with-http_ssl_module –with-openssl=
options.

通过下面的命令安装上OpenSSL解决这个问题:

sudo apt-get install libssl-dev

CYGWIN 中若要使用apt-get的方式安装,可安装如下利器


wget http://apt-cyg.googlecode.com/svn/trunk/apt-cyg

chmod +x apt-cyg

mv apt-cyg /usr/local/bin/

apt-cyg install bc


  • 超简单的图片服务配置,更改nginx.conf或另外新建已.conf结尾的文件

    具体配置可分普通和正则,具体可以查看http://wiki.nginx.org/NginxHttpCoreModule#location

   

#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 {
    #use     epoll;
    worker_connections  64;#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;

        #静态文件,nginx自己处理 location ~ ^/(images|javascript|js|css|flash|media|static)/
        location ~ ^/iyuxl/.*\.(gif|jpg|jpeg|png|bmp|swf|ico)$ {
            root /home;
            #过期30天,静态文件不怎么更新,过期可以设大一点,如果频繁更新,则可以设置得小一点。
            expires 30d;
        }

         location / {
            root   html;
            #root    /home/iyuxl;
            autoindex on;
            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;
    #    server_name  localhost;

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

    #    ssl_session_timeout  5m;

    #    ssl_protocols  SSLv2 SSLv3 TLSv1;
    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers   on;

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








简单配置后,可通过./nginx -t -c  /usr/local/nginx/nginx-yuxl.conf 检验配置文件是否格式准确;

./nginx -c  /usr/local/nginx/nginx-yuxl.conf  进行启动;

ps -ef|grep nginx 查看启动的2个进程;

  • 成功部署后,浏览器上输入:http://IP/图片 ,即可;

后续将增加其他配置。







你可能感兴趣的:(NGINX初试)