nginx配置将带跨域处理的dist映射到9001端口上
时间: 2024-05-11 22:15:42 浏览: 96
好的,这是一个技术问题。您可以使用如下的nginx配置来将带跨域处理的dist映射到9001端口上:
```
server {
listen 80;
server_name yourdomain.com;
location / {
root /path/to/dist;
try_files $uri $uri/ /index.html;
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, 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';
}
}
server {
listen 9001;
server_name yourdomain.com;
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://127.0.0.1:9000;
}
}
```
请注意将 `yourdomain.com` 替换为您的域名,`/path/to/dist` 替换为您的dist目录的路径, `http://127.0.0.1:9000` 替换为您要映射到的后端服务的地址。
阅读全文