Nginx跨域配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84

erver {
listen 81 default_server;
listen [::]:81 default_server;
server_name _;
#root /home/crm_ui_test/dist;

access_log /home/nginx/log/crm_ui_dev_access.log main;

# Load configuration files for the default server block.
#include /etc/nginx/default.d/*.conf;
location / {

root /home/crm_ui_dev/dist;
try_files $uri $uri/ /index.html;
index index.html index.htm;

}

location /server {

proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr; #»ñÈ¡Õæʵip
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;#»ñÈ¡´úÀíÕßµÄÕæʵip
proxy_redirect off;
proxy_pass http://127.0.0.1:85/;
}
}
server_name localhost;
root /home/crm_server_dev/public;

# add_header X-Frame-Options "SAMEORIGIN";
# add_header X-XSS-Protection "1; mode=block";
# add_header X-Content-Type-Options "nosniff";

index index.html index.htm index.php;

charset utf-8;
fastcgi_read_timeout 1000;

access_log /home/nginx/log/crm_server_dev_access.log main;

location / {
try_files $uri $uri/ /index.php?$query_string;
}

location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }

error_page 404 /index.php;
location ~ \.php$ {



if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, PATCH, DELETE, PUT, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type, Access-Control-Expose-Headers, Token, Authorization';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
return 204;
}

add_header 'Access-Control-Allow-Origin' '*' always;
root /home/crm_server_dev/public;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

location ~ /\.(?!well-known).* {
deny all;
}
}

`