mac nginx 虚拟机配置

myb.local.conf

`server {
listen 80 default_server;
root /Users/x/web/m_api/Public;

client_max_body_size 50m;
location /h5/ {
    charset  utf-8;
    index index.html;
    root /Users/x/web/m_api/Public;
    try_files $uri $uri/ /h5/index.html?$query_string;
}
location /a/ {
    charset  utf-8;
    index index.html;
    root /Users/x/web/m_api/Public;
    try_files $uri $uri/ /a/index.html?$query_string;
}

location / {
    root /Users/x/web/m_api/Public;
    #允许跨域
    add_header 'Access-Control-Allow-Origin' $http_origin;
    add_header 'Access-Control-Allow-Credentials' 'true';
    add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
    add_header 'Access-Control-Allow-Headers' 't-host,t-token,t-client';
    add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
    if ($request_method = 'OPTIONS') {
            add_header 'Access-Control-Allow-Origin' $http_origin;
    add_header 'Access-Control-Allow-Credentials' 'true';
    add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
    add_header 'Access-Control-Allow-Headers' 't-host,t-token,t-client';
    add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';

            return 204;
    }
    proxy_http_version 1.1;
    proxy_set_header Connection "keep-alive";
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Host      $host;
    if (!-f $request_filename) {
         proxy_pass http://127.0.0.1:9501;
    }
}

}`

posted @ 2020-09-29 23:49  geek程序员  阅读(209)  评论(0)    收藏  举报