鍍金池/ 問(wèn)答/PHP/ 如何優(yōu)化跨域請(qǐng)求時(shí)OPTIONS的請(qǐng)求速度(NGINX)

如何優(yōu)化跨域請(qǐng)求時(shí)OPTIONS的請(qǐng)求速度(NGINX)

因?yàn)榻涌谏婕暗娇缬騿?wèn)題,每次接口請(qǐng)求時(shí)都有接近600毫秒是OPTIONS請(qǐng)求浪費(fèi)的時(shí)間,如何優(yōu)化這一過(guò)程,例如 nginx 配置跨域直接返回而不經(jīng)過(guò)程序處理(php)

回答
編輯回答
鐧簞噯

跨域也走你本域的ngx?還是你本域的ngx在做跨域的代理?


ngx設(shè)置:

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;
}
2017年11月13日 01:51