Nginx 初探:Nginx+IIS

来源:互联网 发布:王宝强剧情反转知乎 编辑:程序博客网 时间:2024/05/04 15:22

Nginx 是一个高性能的 Web 和反向代理服务器, 它具有有很多非常优越的特性:

作为 Web 服务器:相比 Apache,Nginx 使用更少的资源,支持更多的并发连接,体现更高的效率,这点使 Nginx 尤其受到虚拟主机提供商的欢迎。能够支持高达 50,000 个并发连接数的响应,感谢 Nginx 为我们选择了 epoll and kqueue 作为开发模型.

作为负载均衡服务器:Nginx 既可以在内部直接支持 Rails 和 PHP,也可以支持作为 HTTP代理服务器 对外进行服务。Nginx 用 C 编写, 不论是系统资源开销还是 CPU 使用效率都比 Perlbal 要好的多。

作为邮件代理服务器: Nginx 同时也是一个非常优秀的邮件代理服务器(最早开发这个产品的目的之一也是作为邮件代理服务器),Last.fm 描述了成功并且美妙的使用经验。

以上内容来自Nginx 中文文档,废话少说,直接上code:

安装Nginx 之后,主要是配置nginx.conf ,参考http://nginx.org/en/docs/ 有完整的module 介绍

配置:
两台webserver 搭载IIS 2013:
本机作为Nginx 做负载均衡服务器

#  power by www.phpStudy.net #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;    #tcp_nodelay on;  fastcgi_connect_timeout 300;  fastcgi_send_timeout 300;  fastcgi_read_timeout 300;  fastcgi_buffer_size 128k;  fastcgi_buffers 4 128k;  fastcgi_busy_buffers_size 256k;  fastcgi_temp_file_write_size 256k;  #gzip  on;  gzip on;  gzip_min_length  1k;  gzip_buffers     4 32k;  gzip_http_version 1.1;  gzip_comp_level 2;  gzip_types       text/plain application/x-javascript text/css application/xml;  gzip_vary on;  gzip_disable "MSIE [1-6].";  server_names_hash_bucket_size 128;  client_max_body_size     100m;   client_header_buffer_size 256k;  large_client_header_buffers 4 256k;  upstream pisa.com  {         server  172.21.223.34:8888 weight=5 max_fails=2 fail_timeout=200s;         server  172.21.223.35:8888 weight=3 max_fails=2 fail_timeout=200s;        keepalive 16;        #ntlm;  }   server {        listen       8888;        server_name  www.pisa.com;        charset utf8;        #charset koi8-r;        #access_log  logs/host.access.log  main;        #root   "E:\CFS\2017 Project\Project\PISA\publish";        location / {           root   html;            index index.html sindex.htm index.php index.cshtml;           autoindex  on;           #proxy_redirect on;           proxy_pass  http://pisa.com;           proxy_http_version 1.1;           proxy_set_header Connection "";           proxy_set_header Host $host;              proxy_set_header X-Real-IP $remote_addr;              proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;            proxy_set_header Authorization $http_authorization;            proxy_temp_file_write_size 64k;              proxy_max_temp_file_size 128m;          }        #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(.*)$  {        #    fastcgi_pass   127.0.0.1:9000;        #    fastcgi_index  index.php;        #    fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;        #   fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;        #   fastcgi_param  PATH_INFO  $fastcgi_path_info;        #   fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;        #    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;    #    }    #}#include vhosts.conf;}

备注:

1.upstream 与proxy_pass 对应虚拟负载均衡主机集群名称一致pisa.com
2.负载均衡可以通过配置权重或者ip_hash 的方式进行,需要注意共享session 的问题参考

最终结果,如果web 网站设置成windows 集成认证,Nginx 官方文档介绍支持NTLM ,但是研究发现免费版不支持, 这一点需要注意,免费版支持form 认证或者匿名认证

附上nginx 命令

打开cmd到nginx 安装目录
1.启动 start nginx
2.修改配置文件后重启 nginx -s reload
3.退出 nginx -s quit 或者 nginx -s stop
4.打开日志 nginx -s reopen
5.查看版本 nginx -v

原创粉丝点击