Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

前端启动报错405 #19

Open
tfssweb opened this issue Jul 16, 2023 · 6 comments
Open

前端启动报错405 #19

tfssweb opened this issue Jul 16, 2023 · 6 comments

Comments

@tfssweb
Copy link

tfssweb commented Jul 16, 2023

前端更改.env文件,指定了VITE_APP_API_BASE_URL=http://后端ip:3002,然后打包了dist,放到了服务器nginx,且前端端口为1002,然后访问后端报错405 Not Allowed
POST http://后端ip:1002/api/user/login/email 405 (Not Allowed)

本地启动前端,连接服务器后端,就正常,不知道啥问题,求解决

@hncboy
Copy link
Collaborator

hncboy commented Jul 16, 2023

请使用 nginx

@tfssweb
Copy link
Author

tfssweb commented Jul 16, 2023

请使用 nginx

报错405就是用的nginx,主要配置如下:

server {
    listen       1002;
    server_name  localhost;
    location / {
        proxy_read_timeout 3600s;
        root   /usr/share/nginx/html;
        index  index.html index.htm;
        try_files $uri $uri/ /index.html;
    }

}

@hncboy
Copy link
Collaborator

hncboy commented Jul 16, 2023

hncboy/ai-beehive#71 请参考这个 nginx 配置,nginx 配的是后端接口。

请使用 nginx

报错405就是用的nginx,主要配置如下:

server {
    listen       1002;
    server_name  localhost;
    location / {
        proxy_read_timeout 3600s;
        root   /usr/share/nginx/html;
        index  index.html index.htm;
        try_files $uri $uri/ /index.html;
    }

}

@tfssweb
Copy link
Author

tfssweb commented Jul 16, 2023

hncboy/chatgpt-web-java#71 请参考这个 nginx 配置,nginx 配的是后端接口。

请使用 nginx

报错405就是用的nginx,主要配置如下:

server {
    listen       1002;
    server_name  localhost;
    location / {
        proxy_read_timeout 3600s;
        root   /usr/share/nginx/html;
        index  index.html index.htm;
        try_files $uri $uri/ /index.html;
    }

}

好的,我试下,,有qq群或者微信群不?

@tfssweb
Copy link
Author

tfssweb commented Jul 16, 2023

hncboy/chatgpt-web-java#71 请参考这个 nginx 配置,nginx 配的是后端接口。

请使用 nginx

报错405就是用的nginx,主要配置如下:

server {
    listen       1002;
    server_name  localhost;
    location / {
        proxy_read_timeout 3600s;
        root   /usr/share/nginx/html;
        index  index.html index.htm;
        try_files $uri $uri/ /index.html;
    }

}

这是更改后的nginx:
worker_processes 1;

events {
worker_connections 1024;
}

http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;

server {
    listen       1002;
    server_name  -;
    index index.html;
    proxy_buffering off;
    root  /usr/share/nginx/html;

    gzip on;
    gzip_buffers 4 16K;
    gzip_comp_level 6;
    gzip_min_length 100;
    gzip_types application/javascript text/css text/xml;
    gzip_disable "MSIE [1-6]\.";
    gzip_vary on;


    location /api/ {
        proxy_pass http://localhost:3002/;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;

        add_header X-Cache $upstream_cache_status;
    }

    location ~ ^/(\.user.ini|\.htaccess|\.git|\.env|\.svn|\.project|LICENSE|README.md) {
        return 404;
    }

}

}

但是现在报错502了
POST http://后端IP:1002/api/user/login/email 502 (Bad Gateway)

@hncboy
Copy link
Collaborator

hncboy commented Jul 24, 2023

不应该吧,是不是后端启动有问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants