为什么我会得到'502 Bad Gateway nginx/1,18.0(Ubuntu)'上我的服务器ap

jk9hmnmh  于 2023-04-29  发布在  Nginx
关注(0)|答案(1)|浏览(120)

我在数字海洋的nginx服务器上运行我的前端和后端应用程序。它工作得很好。突然,我得到错误'502 Bad Gateway nginx/1。18.0(Ubuntu)'当我尝试运行应用程序时。
如果我运行sudo nginx -t,得到nginx: configuration file /etc/nginx/nginx.conf test is successful
这是我的配置文件

server {
    listen 80;
    server_name mydomain.com;
    rewrite ^/(.*) https+//mydomain.com/$1 permanent;
}

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

        #listen 80;
        #server_name mydomain.com;
        #rewrite ^/(.*) https+//mydomain.com/$1 permanent;

        listen 443 ssl;
        listen [::]:443 ssl;

        # SSL configuration
       

        root /var/www/html;

        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;

        #server_name _;
        server_name mydomain.com;
        ssl_certificate /home/admin/mydomain.com.chained.crt;
        ssl_certificate_key /home/admin/mydomain.com.key;

location / {
        proxy_pass http://localhost:3000;
        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;
    }

location /api {
        proxy_pass http://localhost:8000;
        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;
    }
}

当我尝试访问www. example时,我会遇到错误 www.example.com
但它与www. example一起工作得很好 www.example.com
帮助取悦任何人
更新我在日志中得到此错误

sudo tail -F /var/log/nginx/error.log

2022/05/03 13:35:31 [error] 791993#791993: *1 connect() failed (111: Connection refused) while connecting to upstream, client: ***.***.***.***, server: mydomain.com, request: "GET /api HTTP/1.1", upstream: "http://127.0.0.1:8080/api", host: "mydomain.com"
dl5txlt9

dl5txlt91#

列表项中的列表:- 缩进四个空格* 缩进八个空格。- 又是四格2.列表项中可以有多个段落。

Just be sure to indent.

相关问题