Ngnix使用

仅作为记录以备忘(nginx/1.12.1)。

ngnix.conf配置样例(有点乱,注释掉的部分主要是用于参考,有的是产品本身的备注,有的是之前使用过的样例)


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

     #服务器的集群  
#    upstream  dyh.com {  #服务器集群名字   
#        server    localhost:8082  weight=1;#服务器配置   weight是权重的意思,权重越大,分配的概率越大。  
#        server    localhost:8081  weight=2;  
#    }   


    server {
        listen       8097 default_server;
        #listen       [::]:8097 default_server;
        server_name  _;

        #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 /rest/ {
#            proxy_pass   https://aip.baidubce.com/rest/;
#	    proxy_redirect	default; 
#        }

        location /v3/auth/tokens {
            proxy_pass   https://iam.cn-north-4.myhuaweicloud.com/v3/auth/tokens;
	    proxy_redirect	default; 
	    proxy_buffer_size  1024k;
	    proxy_buffers   32 1024k;
	    proxy_busy_buffers_size 1024k;
	    fastcgi_buffer_size 1024k;
	    fastcgi_buffers 8 1024k;
            fastcgi_busy_buffers_size 1024k;
        }

	location / {
            proxy_pass   https://ocr.cn-north-4.myhuaweicloud.com/;
	    proxy_redirect	default; 
	    proxy_buffer_size  1024k;
	    proxy_buffers   32 1024k;
	    proxy_busy_buffers_size 1024k;
	    fastcgi_buffer_size 1024k;
	    fastcgi_buffers 8 1024k;
            fastcgi_busy_buffers_size 1024k;
        }

	client_header_buffer_size 32k;
	large_client_header_buffers 8 32k;

        #location / {
        #    proxy_pass   https://aip.baidubce.com/;
	#    proxy_redirect	default; 
        #}


        # 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  aip.baidubce.com;
#
#        ssl_certificate      ../shidian.crt;
#        ssl_certificate_key  ../shidian.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;
#        #}
#        location /rest/ {
#            proxy_pass   https://aip.baidubce.com/rest/;
#            proxy_redirect	default; 
#        }
#
#    #    location / {
#    #       proxy_pass   https://aip.baidubce.com/;
#    #	    proxy_redirect	default; 
#    #    }
#    }

}

#号为注释。

精简后的配置(又贴一次代码)


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

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        #监听8097端口,例如ngnix部署在本地,那发起http://localhost:8097的请求就会请求到ngnix了
        listen       8097 default_server;
        server_name  _;

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        #注意,配置了多个location,那会按上至下顺序匹配,如果上面的已经匹配则走匹配的,不再往下匹配,否则依顺序继续匹配到最好一个为止。
        #如果URL路径中包含“/v3/auth/tokens”,
        #就请求https://iam.cn-north-4.myhuaweicloud.com/v3/auth/tokens
        location /v3/auth/tokens {
            proxy_pass   https://iam.cn-north-4.myhuaweicloud.com/v3/auth/tokens;
	        proxy_redirect	default; 
	        #设置了一些缓存之类的配置
            proxy_buffer_size  1024k;
	        proxy_buffers   32 1024k;
	        proxy_busy_buffers_size 1024k;
	        fastcgi_buffer_size 1024k;
	        fastcgi_buffers 8 1024k;
            fastcgi_busy_buffers_size 1024k;
        }
        #所有请求,
        #都转为请求https://ocr.cn-north-4.myhuaweicloud.com/的资源,
        #域名后的资源路径和原始的是一样的
        #如http://localhost:8097/v1.0/ocr/id-card,经过ngnix后
        #就变成请求https://ocr.cn-north-4.myhuaweicloud.com/v1.0/ocr/id-card
	    location / {
            proxy_pass   https://ocr.cn-north-4.myhuaweicloud.com/;
	        proxy_redirect	default; 
	        ##设置了一些缓存之类的配置
            proxy_buffer_size  1024k;
	        proxy_buffers   32 1024k;
	        proxy_busy_buffers_size 1024k;
	        fastcgi_buffer_size 1024k;
	        fastcgi_buffers 8 1024k;
            fastcgi_busy_buffers_size 1024k;
        }
    #以下两行配置,处理如400 Request Header Or Cookie Too Large这种问题
	client_header_buffer_size 32k;
	large_client_header_buffers 8 32k;
    }
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值