【发布时间】:2022-11-11 12:34:43
【问题描述】:
我创建了一个网站 example.com,其中有两个名为“服务”和“想法”的部分是动态数据。来自http://api.example.com/ourservice.json & http://api.example.com/ideas.json
在我的项目中,当我在 localhost 中运行它时,它正在从 API 中获取这些数据,但是当我在服务器中上传 react build 文件夹时,它并没有获取这些数据。
有什么我想念的吗?是API的问题吗?
在 api.example.com 的配置文件的 nginx 中,我有这个配置
server {
# Binds the TCP port 80.
listen 80;
# Root directory used to search for a file
root /var/www/html/example_static_api;
# Defines the file to use as index page
index index.html index.htm;
# Defines the domain or subdomain name.
# If no server_name is defined in a server block then
# Nginx uses the 'empty' name
server_name api.example.com;
location / {
# Return a 404 error for instances when the server receives
# requests for untraceable files and directories.
try_files $uri $uri/ =404;
add_header Access-Control-Allow-Origin *;
}
}
有什么我想念的吗!
【问题讨论】:
标签: javascript reactjs nginx