Nginx

来源:互联网 发布:网络平台合作合同范本 编辑:程序博客网 时间:2024/05/17 03:03

在非window下安装:

链接:http://www.cnblogs.com/skynet/p/4146083.html



windows下安装以及配置nginx

    链接:http://jingyan.baidu.com/article/f3e34a12a9c1c3f5eb6535d4.html
    nginx官网:http://nginx.org/en/download.html

nginx中设置多个站点问题:virtual host
链接:http://www.2cto.com/os/201411/355976.html

nginx的使用:

运行nginx.exe. 将web中的页面放入到nginx指定路径下,然后,直接输入路径就好了,就可以访问这些页面了。
nginx中的web页面是静态的,不想jsp,php那样。如果要为php是要再设置php服务器。

tomcat与nginx之间的区别为:

1.tomcat集成了servlet框架,可以是使用jsp等动态页面。

2.nginx做的主要是反向代理


nginx就是反向代理服务器,反向代理就是:客户端C1发送请求到反向代理服务器N,N选择一台业务服务器S1进行处理,将处理结果返回给N,N将结果发送给C1。

                                                                               客户端C2发送请求到反向代理服务器N,N选择一台业务服务器S2进行处理,将处理结果返回给N,N将结果发送给C2。

总之:C1、C2都不知道你们具体访问的业务服务器是谁,只有nginx知道。


nginx配置

非常详细:链接:http://www.ha97.com/5194.html

 常用配置如下:   Nginx.conf代码   http {    server {    #1.侦听80端口    listen 80;    location / {    # 2. 默认主页目录在nginx安装目录的html子目录。    root html;    index index.html index.htm;    # 3. 没有索引页时,罗列文件和子目录    autoindex on;    autoindex_exact_size on;    autoindex_localtime on;    }    # 4.指定虚拟目录    location /tshirt {    alias D:\programs\Apache2\htdocs\tshirt;    index index.html index.htm;    }    }    # 5.虚拟主机www.emb.info配置    server {    listen 80;    server_name www.emb.info;    access_log emb.info/logs/access.log;    location / {    index index.html;    root emb.info/htdocs;    }    }   }     http {   server {   #1.侦听80端口    listen 80;    location / {   # 2. 默认主页目录在nginx安装目录的html子目录。   root html;   index index.html index.htm;   # 3. 没有索引页时,罗列文件和子目录   autoindex on;   autoindex_exact_size on;   autoindex_localtime on;   }   # 4.指定虚拟目录   location /tshirt {   alias D:\programs\Apache2\htdocs\tshirt;   index index.html index.htm;   }   }   # 5.虚拟主机www.emb.info配置   server {   listen 80;   server_name www.emb.info;   access_log emb.info/logs/access.log;   location / {   index index.html;   root emb.info/htdocs;   }   }  }  


在一个http{}中设置多个server{},表示设置了多个服务器,这些server对象中的,server_name和listen组合是不一样的。

这里面就配置了两台服务器:端口号分别为8008,8009

#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       8008;        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       8009;        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;    #    }    #}}




0 0
原创粉丝点击