nginx小技巧
预请求
if ($request_method = OPTIONS ) { add_header Access-Control-Allow-Origin "*"; add_header Access-Control-Allow-Methods "POST, GET, PUT, OPTIONS, DELETE"; add_header Access-Control-Max-Age "3600"; add_header Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept, Authorization"; add_header Content-Length 0; add_header Content-Type text/plain; return 200; }
备注: 需要放在location节点下面
yarn错误The engine "node" is incompatible with this module
yarn config set ignore-engines true
转发简单例子
server{ listen 80; server_name kjwoo.cn.test; index index.php index.html index.htm; location / { proxy_pass http://192.168.1.9:3300; } }
写日志
server{ listen 80; server_name kjwoo.cn.test; index index.php index.html index.htm; log_format log_json '{"@timestamp": "$time_local","user_ip":"$http_x_real_ip","lan_ip":"$remote_addr","log_time":"$time_iso8601","user_req":"$request","http_code":"$status","body_bytes_sents":"$body_bytes_sent","req_time":"$request_time","user_ua":"$http_user_agent"}'; access_log /var/log/nginx/access.log log_json; location / { proxy_pass http://192.168.1.9:3300; } }