openresty postgresql 모듈 추가
                                            
 4158 단어  nginx
                    
yum install  postgresql-devel2. nginx conf 에 location 설정:
location /postgres {
	    internal;
	    default_type text/html;
	    set_by_lua_block $query_sql {return ngx.unescape_uri(ngx.var.arg_sql)}
	    
	    postgres_pass   pg_server;
	    rds_json          on;
	    rds_json_buffer_size 16k;
	    postgres_query  $query_sql;
	    postgres_connect_timeout 1s;
	    postgres_result_timeout 2s;
	}3. upstream 설정
upstream pg_server {
    postgres_server  192.168.0.103:5432 dbname=fame
            user=postgres password=root;
    postgres_keepalive max=800 mode=single overflow=reject;
}4. lua 파일 중:
-- postgres     ,  JSON     
function queryDataPostgres()
	local res = ngx.location.capture('/postgres',
            { args = {sql = "select user_id,user_name from fame_user where 1=1 limit 5 offset 0 " } }
	)
	local status = res.status
	--        ,  json         
	local body = readJson(res.body)
	if status == 200 then
		--          , JSON     
		return respData2Client(body)
	else
		return callerror()
	end
이상 전단 요청 을 받 은 후 postgres 모듈 로 전송 요청 을 조회 할 수 있 습 니 다. 조 회 된 데 이 터 는 JSON 형식 입 니 다.
5. nginx 에서 api 입구 설정:
listen       80;
	server_name  192.168.58.128;#    
	charset utf-8;
	location /fameapi {
	    
	    default_type application/json;
	    access_by_lua_file ../lua/hight_limit_speed.lua; # lua  
	    proxy_buffer_size 64k;
            proxy_buffers   32 32k;
            proxy_busy_buffers_size 128k;         
            proxy_pass     http://fameapi; #    
            proxy_set_header   X-Real-IP $remote_addr;
      	    proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
      	    proxy_set_header    Host $host;
            proxy_pass_header    User-Agent;
      	    client_max_body_size 100M;
	    proxy_connect_timeout 60;#nginx            (      )
	    proxy_send_timeout 60;#           (      )
	    proxy_read_timeout 60;#     ,         (      )
	}참조 원본:https://moonbingbing.gitbooks.io/openresty-best-practices/content/postgres/how_to_use.html
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
간단! Certbot을 사용하여 웹 사이트를 SSL(HTTPS)화하는 방법초보자가 인프라 주위를 정돈하는 것은 매우 어렵습니다. 이번은 사이트를 간단하게 SSL화(HTTP에서 HTTPS통신)로 변경하는 방법을 소개합니다! 이번에는 소프트웨어 시스템 Nginx CentOS7 의 환경에서 S...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.