在安裝好nginx後打開nginx的配置檔案.或者打開指定vhost的配置檔案.如果不知道檔案位置的話可以使用: nginx -t
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
那麼打開配置檔案
vim /usr/local/etc/nginx/nginx.conf
添加
underscores_in_headers on;
`add_header Access-Control-Allow-Origin $http_origin;
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' '*';
add_header Access-Control-Allow-Headers 'XMLHttpRequest, X_FILENAME, accept-encoding, authorization, content-type, dnt, origin, appid, user-agent, x-csrftoken, x-requested-with, cache-control, from, postman-token, x-http-appid, x-http-device, Pragma, farmorg, orgcode,token,app-id,app_id';`
儲存退出後重新開機nginx即可.