Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

502 bad gateway mvc core app on CentOS

I made a website in MVC Core and tried to publish it to the web on a CentOS 7 VPS. It runs well, when I curl it it responds. Then i installed nginx and it showed the default page, when trying it from my computer. Then i changed nginx.conf to the below one and all i get is 502 bad gateway. In the nginx log i see only that a get request was received. Any ideas what should i check?

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/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;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    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;
        location / {
            proxy_pass http://localhost:5000;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection keep-alive;
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;
        }
     } 
}
like image 349
Robert Avatar asked Jul 08 '17 10:07

Robert


People also ask

What is 502 Bad gateway error mean?

The HyperText Transfer Protocol (HTTP) 502 Bad Gateway server error response code indicates that the server, while acting as a gateway or proxy, received an invalid response from the upstream server.

How to handle 502 error in java?

Clear Your Browser's Cache and Cookies If trying a different browser works, your main browser may have cached outdated or corrupt files that might be causing the 502 error. Removing these cached files and trying to open the website could solve the problem.

What does 502 bad gateway registered endpoint failed to handle the request?

Webserver overload: If a webserver reaches its limit, it can't answer any more requests — the gateway then delivers the status code 502 Bad Gateway. The reason could be an unexpectedly high interest in the site or even a DDoS attack.


1 Answers

I tried apache and had the same problem. Then i found the solution, you have to set httpd_can_network_connect.

http://sysadminsjourney.com/content/2010/02/01/apache-modproxy-error-13permission-denied-error-rhel/

A didn't find the error message in the audit blog that the author was talking about but i tried his solution and it worked.

I have used centos for 4 days now and it's the second time i have to set a bit to solve a problem. These solutions are quite hidden in the web and most articles dealing with the area doesn't mention those so i lost a lot of time. So i share the opinion of the author about SELinux. Probably i will try another linux distribution. What is also interesting that I followed the official microsoft tutorial "Set up a hosting environment for ASP.NET Core on Linux with Apache, and deploy to it". The operating system that they use is CentOS too. And it doesn't mention this bit either.

like image 61
Robert Avatar answered Oct 08 '22 14:10

Robert