nginx config配置(windows)

#user nobody;启动进程,通常设置成和cpu的数量相等 worker_processes 1;

#全局错误日志及PID文件 #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; #单个后台worker process进程的最大并发链接数 }

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; #该指令用于开启或关闭gzip模块(on/off)
gzip_min_length 1k;#设置允许压缩的页面最小字节数,页面字节数从header头得content-length中进行获取。默认值是0
gzip_buffers 16 64k; #设置系统获取几个单位的缓存用于存储gzip的压缩结果数据流。4 16k代表以16k为单位,安装原始数据大小以16k为单位的4倍申请内存
gzip_http_version 1.1; #http的协议版本(1.0/1.1)
gzip_comp_level 1;#gzip压缩比,1压缩比最小,处理速度最快,9压缩比最大但处理速度最慢(传输快但比较消耗cpu)
gzip_types text/javascript application/x-javascript text/css application/xml;
gzip_vary on;

upstream www.test.com {
server xxx.xxx.xxx
server xxx.xxx.xxx	
server xxx.xxx.xxx	
server xxx.xxx.xxx;		   
 }

#gzip  on;

server {
    listen       80;
    server_name  192.168.6.110;

    #charset koi8-r;

    #access_log  logs/host.access.log  main;

    location / {
        #root   html;
        #index  index.html index.htm;
    proxy_pass http://www.test.com;
    proxy_redirect default;
        #设置主机头和客户端真实地址,以便服务器获取客户端真实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;
    }

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

}

C#  Request.Headers["X-Real-IP"];  获取代理ip

nginx 服务 自动启动

下载winsw-1.8-bin 解压后 重命名XXX.exe 然后创建 同名.XML <service>
<id>nginx</id>
<name>nginx</name>
<description>nginx</description>
<executable>e:\nginx\nginx.exe</executable>
<logpath>e:\nginx\logs</logpath>
<logmode>roll</logmode>
<depend></depend>
<startargument>-p e:\nginx</startargument>
<stopargument>-p e:\nginx -s stop</stopargument>
</service>

路劲根据nginx 设置

然后 管理员模式 cmd 进入nginx目录 名字.exe install

管理员模式 CMD 强行关闭nginx进程 输入图片说明

重置conf nginx -c /nginx/conf/nginx.conf

nginx 一个端口监听多个站点

缓冲设定 client_header_buffer_size 32k; large_client_header_buffers 4 32k;

配置多个 upstream www.test.com { server xxx.xxx.xxx;
}

upstream www.test1.com { server xxx.xxx.xxx;
}

对应配置server

server { listen 80; server_name xxx;

    #charset koi8-r;

    #access_log  logs/host.access.log  main;

    location / {
        #root   html;
        #index  index.html index.htm;
    proxy_pass www.test.com;
    #proxy_redirect default;
    #设置主机头和客户端真实地址,以便服务器获取客户端真实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;
    }


location /status {  
         allow xxx.xxx.xxx;  
         allow xxx.xxx.xxx;  
         deny all;  
         stub_status on;  
         access_log  off;  
    }  

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

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}


server {
    listen       80;
    server_name  xxx;

    #charset koi8-r;

    #access_log  logs/host.access.log  main;

    location / {
        #root   html;
        #index  index.html index.htm;
    proxy_pass www.test1.com;
    #proxy_redirect default;
    #设置主机头和客户端真实地址,以便服务器获取客户端真实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;
    }


location /status {  
         allow xxx.xxx.xxx;
         deny all;  
         stub_status on;  
         access_log  off;  
    }  

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

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

转载于:https://my.oschina.net/u/1759685/blog/647256

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值