使用spring后端为react应用程序设置nginx

72qzrwbm  于 7个月前  发布在  Spring
关注(0)|答案(1)|浏览(100)

我们正在尝试做运行React应用程序与nginx,但我们不能React后端API从React应用程序。


的数据
这是我的配置




关于Docker Start

docker run -d -p 3333:80 -m 3g --name gagu-react gagu-react:latest

字符串
然后在Docker运行后运行此命令。

docker cp spring.conf gagu-react:/etc/nginx/conf.d/spring.conf

docker exec gagu-react nginx -s reload


它的显示成功,我验证了使用猫文件其显示正确的配置
成功复制2.05kB到gagu-react:/etc/nginx/conf. d/spring. conf
2023/11/05 18:53:49 [notice] 11#11:信号处理开始
它的gagu-react docker日志
2023/11/05 18:57:58 [错误] 19#19:* 3 open()"/usr/share/nginx/html/API/gameType/getAll "失败(2:没有这样的文件或目录),客户端:www.example.com,服务器:localhost,请求:" GET/API/gameType/getAll HTTP/1.1 ",主机:"xx.xxx.xxx.1:3333",发布者:"http://xx.xxx.xxx.1:3333/"www.example.com--[05/Nov/2023:18:57:+0000]" GET/API/gameType/getAll HTTP/1.1 "404 555" http://xx.xxx.xxx.1:3333/""Mozilla/5.0(Windows NT 10.0; Win64; x64)AppleWebKit/537.36(KHTML,如Gecko)Chrome/www.example.com Safari/537.36""-"
有人能帮我们吗

q1qsirdb

q1qsirdb1#

使用spring后端为react应用程序设置nginx
我认为配置是错误的。通常,在/etc/nginx/conf.d内部还有配置为侦听端口80的文件default.conf。目前它正在使用/usr/share/nginx/html文件夹内的文件进行应答。
要解决此问题,您需要:
1.更新default.conf并添加API的代理传递(如spring.conf中所示);
1.删除spring.conf文件。
你应该尝试这样的配置:

server {
        listen 80;
        listen [::]:80;

        root /usr/share/nginx/html;
        index index.html index.htm;

        location / {
                try_files $uri $uri/ =404;
        }
    location /api {
        proxy_pass http...
        proxy_set_header...
        }
}

字符串

相关问题