Nginx跨域配置 发表于 2020-07-26 更新于 2020-07-27 分类于 Nginx 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384erver { 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; }} `