server {
listen 80;
listen 443 ssl;
server_name xxx;
ssl_certificate /usr/local/nginx/conf/ssl/xxx.com.pem;
ssl_certificate_key /usr/local/nginx/conf/ssl/xxx.com.key;
ssl_protocols TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Method $request_method;
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
}
}
前端项目配置了跨域,代码如下:
import { defineConfig } from "vite";
export default defineConfig({
...
server: {
open: true,
proxy: {
"/api": {
target: nginx 中配置的 server_name ,
changeOrigin: true,
},
},
},
...
});
请各位大哥指点一下
Nginx, add_header, proxy_set_header, SSL