我是saleor.io的新手,这是一个用于电子商务应用程序和nginx的开源平台。该销售商具有三个模块:
我正在nginx上运行这三个模块,并且每个模块的UI都显示得很好。但是当我尝试通过仪表板登录时,出现了CORS错误:
这是我用于saleor核心的nginx配置文件:
upstream django {
server unix:///home/umair/PythonDjangoProjects/GitSaleor/mysite.sock fail_timeout=9000; # for a file socket
# server 192.168.0.102:80; # for a web port socket (we'll use this first)
}
# configuration of the server
server {
# the port your site will be served on
listen 80;
# the domain name it will serve for
server_name 192.168.0.102; # substitute your machine's IP address or FQDN
charset utf-8;
# max upload size
client_max_body_size 75M; # adjust to taste
# Django media
location /media {
alias /home/umair/PythonDjangoProjects/GitSaleor/media; # your Django project's media files - amend as required
}
location /static {
alias /home/umair/PythonDjangoProjects/GitSaleor/static; # your Django project's static files - amend as required
}
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass django;
include /home/umair/PythonDjangoProjects/GitSaleor/uwsgi_params; # the uwsgi_params file you installed
} }
这是我的用于销售商仪表板的nginx配置文件:
server {
listen 70;
listen [::]:70;
root /var/www/html/dashboard;
index index.html;
server_name 192.168.0.102;
location / {
try_files $uri $uri/ /index.html?$args;
}
}
如何解决此错误?我是否在配置中缺少任何内容。
答案 0 :(得分:0)
我认为您应该尝试放置
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
}
if ($request_method = 'POST') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
}
if ($request_method = 'GET') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
}
在您的销售商核心位置区域内。