提问人:Keller Hellen 提问时间:10/12/2023 更新时间:10/12/2023 访问量:21
当我使用 AWS ec2 的 Nginx 时,站点已被 Cors 策略阻止
Site has been blocked by Cors policy when I use Nginx of AWS ec2
问:
我正在尝试在 AWS ec2 服务器上运行 react 项目。 所以我部署了节点服务器并在 Ec2 实例中构建了 react 项目。 我正在尝试在节点服务器和构建的 react 项目之间进行连接。 我正在使用 Nginx 服务器。 这是 nginx.conf 文件内容。
`# For more information on configuration, see: `# \* Official English Documentation: http://nginx.org/en/docs/
# \* Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/\*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user \[$time_local\] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
keepalive_timeout 65;
types_hash_max_size 4096;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
server {
listen 80;
listen [::]:80;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
error_page 404 /404.html;
location = /404.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
server {
server_name proqureng.com;
root /var/www/client;
index index.html;
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/proqureng.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/proqureng.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
listen 80;
listen \[::\]:80;
server_name proqureng.com;
location / {
add_header Access-Control-Allow-Origin *;
proxy_pass https://localhost:5005;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
server {
listen 80;
listen \[::\]:80;
server_name python.proqureng.com;
location / {
add_header Access-Control-Allow-Origin *;
proxy_pass https://3.11.83.44:5003;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
server {
listen 80;
server_name admin.proqureng.com;
root /var/www/admin;
index index.html;
}
server {
listen 80;
listen [::]:80;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
error_page 404 /404.html;
location = /404.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
server {
listen 5001;
server_name 3.11.83.44;
root /var/www/admin;
index index.html;
}
server {
listen 5002;
server_name 3.11.83.44;
root /var/www/client;
index index.html;
}
server {
listen 80;
server_name www.proqureng.com;
return 301 $scheme://proqureng.com$request_uri;
}
# Settings for a TLS enabled server.
#
# server {
# listen 443 ssl http2;
# listen \[::\]:443 ssl http2;
# server_name \_;
# root /usr/share/nginx/html;
#
# ssl_certificate "/etc/pki/nginx/server.crt";
# ssl_certificate_key "/etc/pki/nginx/private/server.key";
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 10m;
# ssl_ciphers PROFILE=SYSTEM;
# ssl_prefer_server_ciphers on;
#
# # Load configuration files for the default server block.
# include /etc/nginx/default.d/\*.conf;
#
# error_page 404 /404.html;
# location = /404.html {
# }
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# }
}\`
我遇到了这样的错误。在此处输入图像描述
我希望有人能解决这个错误。 谢谢
我想在 AWS Ec2 上运行前端和后端。 我想解决这个问题。
答: 暂无答案
评论