nginx整理(一)

nginx入门

什么是nginx

nginx是一款高性能的http 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器。由俄罗斯的程序设计师Igor Sysoev所开发,官方测试nginx能够支支撑5万并发链接,并且cpu、内存等资源消耗却非常低,运行非常稳定,所以现在很多知名的公司都在使用nginx。

应用场景

  1. http服务器
  2. 虚拟主机
  3. 反向代理

配置(细节见注解)


#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 {
    limit_req_zone $binary_remote_addr zone=one:10m rate=30r/m;
    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;

    

    # another virtual host using mix of IP-, name-, and port-based configuration
	
# 负载均衡配置

	# 轮询配置
	#upstream backserver { 
     #server 127.0.0.1:8080 ; 
     #server 127.0.0.1:8081 ; 
    #} 
	
	# 根据权重配置
	#upstream backserver { 
     #server 127.0.0.1:8080 weight=1; 
     #server 127.0.0.1:8081 weight=3; 
    #} 
	
	# 根据ip hash
	#upstream backserver { 
	 #ip_hash; 
	 #server 192.168.0.1:80; 
	 #server 192.168.0.2:80; 
	#} 

	
	#  nginx 防盗链配置
	#location ~ .*\.(jpg|jpeg|JPG|png|gif|icon)$ {
    #    valid_referers blocked http://www.lidaxia.top;
    #    if ($invalid_referer) {
    #        return 403;
    #    }
	#	}


    # 防止ddos(Distributed Denial of Service  分布式拒绝服务) 攻击   (限制请求速度)
	limit_req_zone $binary_remote_addr zone=one:10m rate=30r/m;
	server {
		proxy_pass  http://127.0.0.1:8080;
		index  index.html index.htm;
		location /login.html {
		limit_req zone=one;
		}
	}


	
    
     server {
        listen       80;
        server_name  www.lidaxia.top;
        location / {
		    proxy_pass  http://127.0.0.1:8080;
			index  index.html index.htm;
			
			# 宕机轮询配置 
			#proxy_connect_timeout 1;
            #proxy_send_timeout 1;
            #proxy_read_timeout 1;

        }
    }
	
	
	###  解决跨域
	#server {
     #   listen       80;
     #   server_name  www.lidaxia.top;
     #   location /A {
	 #	    proxy_pass  http://a.a.top:81/A;
	 #		index  index.html index.htm;
     #   }
	 #	location /B {
	 #	    proxy_pass  http://b.b.top:81/B;
	 #		index  index.html index.htm;
     #   }
    #}

	
	
     server {
        listen       80;
        server_name  b8081.lidaxia.top;
        location / {
		    proxy_pass  http://127.0.0.1:8081;
			index  index.html index.htm;
        }
    }
    # 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;
    #    }
    #}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值