Nginx + IIS Usage Introduction

Source: Internet
Author: User
Tags sendfile nginx server

1. Download Nginx

2. Configuring Nginx Files

1) Configure the directory under E:\nginx\nginx-1.9.3\conf:

#user nobody;worker_processes1; #error_log logs/Error.log, #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid;events {worker_connections1024x768;}    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_timeout0; Keepalive_timeout $;    #gzip on; Upstream localhost {server127.0.0.1: theweight=1; Server127.0.0.1: theweight=2; } Server {Listen -;        server_name localhost; #charset Koi8-S; #access_log logs/Host.access.log Main; Location/{proxy_pass http://localhost;Proxy_redirectdefault; } #error_page404/404. html; # REDIRECT Server error pages to theStaticPage/50x.html # Error_page - 502 503 504/50x.html; Location= /50x.html {root html; } # Proxy The PHP scripts to Apache listening on127.0.0.1: the# #location~\.php$ {# Proxy_pass http://127.0.0.1;#} # Pass the PHP scripts to FastCGI server listening on127.0.0.1:9000# #location~\.php$ {# root HTML; # Fastcgi_pass127.0.0.1:9000;        # Fastcgi_index index.php; # Fastcgi_param Script_filename/Scripts$fastcgi_script_name;        # include Fastcgi_params; #} # Deny access to. htaccess files,ifApache's Document Root# concurs with Nginx'S One# #location~ /\.ht {# deny all; #}} # anotherVirtualHostusingMix of ip-, name-, and port-based configuration # #server {# listen8000; # Listen Somename:8080;    # server_name somename alias Another.alias; # Location/{# root HTML;    # index index.html index.htm; #} #} # HTTPS Server # #server {# listen443SSL;    # 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; #    }    #}}

3. deployment of two Web sites in IIS: 127.0.0.1:80, 127.0.0.1:82

4. The effect is as follows:

Nginx Related use command:

Verify that the configuration is correct: nginx-t

View Nginx version number: Nginx-v

Start Nginx:start Nginx

Quick Stop or close nginx:nginx-s stop

Normal stop or close nginx:nginx-s quit

Configuration file Modification Reload command: Nginx-s Reload

Nginx Configuration File Detailed description

In this record the Nginx server nginx.conf configuration file description, some comments collected with the network.

#运行用户
User Www-data;
#启动进程, usually set to equal to the number of CPUs
Worker_processes 1;

#全局错误日志及PID文件
Error_log/var/log/nginx/error.log;
Pid/var/run/nginx.pid;

#工作模式及连接数上限
Events {
Use Epoll; One way in #epoll是多路复用IO (I/O multiplexing), but only for linux2.6 above the core, can greatly improve the performance of Nginx
Worker_connections; Maximum number of concurrent links #单个后台worker process processes
# multi_accept on;
}

#设定http服务器, using its reverse proxy function to provide load balancing support
HTTP {
#设定mime类型, the type is defined by the Mime.type file
Include/etc/nginx/mime.types;
Default_type Application/octet-stream;
#设定日志格式
Access_log/var/log/nginx/access.log;

#sendfile instruction Specifies whether Nginx calls the Sendfile function (zero copy mode) to output the file, for normal applications,
#必须设为 on, if used for downloading applications such as disk IO heavy load applications, can be set to off to balance disk and network I/O processing speed and reduce system uptime.
Sendfile on;
#tcp_nopush on;

#连接超时时间
#keepalive_timeout 0;
Keepalive_timeout 65;
Tcp_nodelay on;

#开启gzip压缩
gzip on;
Gzip_disable "MSIE [1-6]\. (?!. *SV1) ";

#设定请求缓冲
Client_header_buffer_size 1k;
Large_client_header_buffers 4 4k;

include/etc/nginx/conf.d/*.conf;
include/etc/nginx/sites-enabled/*;

#设定负载均衡的服务器列表
Upstream Mysvr {
#weigth参数表示权值, the higher the weight, the greater the chance of being assigned.
#本机上的Squid开启3128端口
Server 192.168.8.1:3128 weight=5;
Server 192.168.8.2:80 weight=1;
Server 192.168.8.3:80 weight=6;
}


server {
#侦听80端口
Listen 80;
#定义使用www. xx.com Access
server_name www.xx.com;

#设定本虚拟主机的访问日志
Access_log Logs/www.xx.com.access.log Main;

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

Fastcgi_pass www.xx.com;
Fastcgi_param script_filename $document _root/$fastcgi _script_name;
Include/etc/nginx/fastcgi_params;
}

# define Error Prompt page
Error_page 502 503 504/50x.html;
Location =/50x.html {
Root/root;
}

#静态文件, Nginx handles it himself.
Location ~ ^/(images|javascript|js|css|flash|media|static)/{
Root/var/www/virtual/htdocs;
#过期30天, the static files are not updated, the expiration can be set a little larger, if updated frequently, you can set a smaller point.
Expires 30d;
}
All #PHP script requests are forwarded to fastcgi processing. Use the fastcgi default configuration.
Location ~ \.php$ {
Root/root;
Fastcgi_pass 127.0.0.1:9000;
Fastcgi_index index.php;
Fastcgi_param Script_filename/home/www/www$fastcgi_script_name;
Include Fastcgi_params;
}
#设定查看Nginx状态的地址
Location/nginxstatus {
Stub_status on;
Access_log on;
Auth_basic "Nginxstatus";
Auth_basic_user_file conf/htpasswd;
}
#禁止访问. htxxx file
Location ~/\.ht {
Deny all;
}

}
}

The above is some basic configuration, the biggest advantage of using Nginx is load balancing

If you want to use load balancing, you can modify the configuration HTTP node as follows:

#设定http服务器, using its reverse proxy function to provide load balancing support
HTTP {
#设定mime类型, the type is defined by the Mime.type file
Include/etc/nginx/mime.types;
Default_type Application/octet-stream;
#设定日志格式
Access_log/var/log/nginx/access.log;

#省略上文有的一些配置节点

#。。。。。。。。。。

#设定负载均衡的服务器列表
Upstream Mysvr {
#weigth参数表示权值, the higher the weight, the greater the chance of being assigned.
Server 192.168.8.1x:3128 weight=5; #本机上的Squid开启3128端口
Server 192.168.8.2x:80 weight=1;
Server 192.168.8.3x:80 weight=6;
}

Upstream MYSVR2 {
#weigth参数表示权值, the higher the weight, the greater the chance of being assigned.

Server 192.168.8.x:80 weight=1;
Server 192.168.8.x:80 weight=6;
}

#第一个虚拟服务器
server {
#侦听192.80 Port of 168.8.x
Listen 80;
server_name 192.168.8.x;

#对aspx后缀的进行负载均衡请求
Location ~. *\.aspx$ {

Root/root; #定义服务器的默认网站根目录位置
Index index.php index.html index.htm; #定义首页索引文件的名称

Proxy_pass http://mysvr; #请求转向mysvr defined list of servers

#以下是一些反向代理的配置可删除.

Proxy_redirect off;

#后端的Web服务器可以通过X-forwarded-for Get the user real IP
Proxy_set_header Host $host;
Proxy_set_header X-real-ip $remote _addr;
Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
Client_max_body_size 10m; #允许客户端请求的最大单文件字节数
Client_body_buffer_size 128k; #缓冲区代理缓冲用户端请求的最大字节数,
Proxy_connect_timeout 90; #nginx跟后端服务器连接超时时间 (proxy connection timed out)
Proxy_send_timeout 90; #后端服务器数据回传时间 (proxy send timeout)
Proxy_read_timeout 90; #连接成功后, back-end server response time (proxy receive timeout)
Proxy_buffer_size 4k; #设置代理服务器 (nginx) buffer size for saving user header information
Proxy_buffers 4 32k; #proxy_buffers缓冲区, the average page is below 32k, so set
Proxy_busy_buffers_size 64k; #高负荷下缓冲大小 (proxy_buffers*2)
Proxy_temp_file_write_size 64k; #设定缓存文件夹大小, greater than this value, will be passed from the upstream server

}

}
}

Nginx + IIS Usage Introduction

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.