NGINX配置解析器不适用于本地主机

时间:2019-09-05 19:45:44

标签: nginx amazon-ec2

我已经在端口4210上运行的nginx上部署了我的项目(角度)。我正在使用aws ec2实例。当我尝试在浏览器上运行项目时,它给我500个内部服务器错误。您能告诉我这是我哪里错了。这是我的第一次。

nginx -t取得了成功,Angular服务器也在工作

----默认服务器配置(站点可用)----

```server {
        listen 80;
        listen [::]:80;
        listen 127.0.0.1;
        proxy_connect_timeout       600s;
        proxy_send_timeout          600s;
        proxy_read_timeout          600s;
        send_timeout                600s;
        set $frontend "http://localhost:4210";
        set $apiBackend "http://localhost:5002";

        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 _;

        location / {

                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header Host $http_host;
                proxy_set_header X-NginX-Proxy true;
                proxy_pass $frontend/$uri$is_args$args;
                proxy_redirect off;
        }

        location /api {

                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header Host $http_host;
                proxy_set_header X-NginX-Proxy true;
                proxy_pass $apiBackend/$uri$is_args$args;
                proxy_redirect off;
        }

   }```
my nginx.conf file ------------

  ```user www-data;
     worker_processes auto;
     pid /run/nginx.pid;
     include /etc/nginx/modules-enabled/*.conf;

     events {
         worker_connections 768;
         # multi_accept on;
     }

     http {
        ##
        # Basic Settings
        ##enter code here

        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        # server_tokens off;
        resolver 127.0.0.1;

        include /etc/nginx/mime.types;
        default_type application/octet-stream;

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
        ssl_prefer_server_ciphers on;

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        ##
        # Gzip Settings
        ##

        gzip on;

        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
     }```

2019/09/05 18:47:47 [错误] 7090#7090:解决时send()失败(111:连接被拒绝),解析器:127.0.0.1:53

2019/09/05 18:47:47 [错误] 7090#7090:解决时send()失败(111:连接被拒绝),解析器:127.0.0.1:53

1 个答案:

答案 0 :(得分:1)

以下是一些解决方案:

  1. 安装dnsmasq:sudo apt-get install dnsmasq,以使本地DNS服务器在127.0.0.1上运行(类似于[1])
  2. 更新nginx配置并将resolver 169.254.169.253设置为对VPC [2]中的EC2实例使用默认的AWS DNS服务器

这是有关dnsmasq [3]的AWS知识中心的链接

[1] https://stackoverflow.com/a/8559797/1224211
[2] https://docs.aws.amazon.com/vpc/latest/userguide/vpc-dns.html#vpc-dns-support
[3] https://aws.amazon.com/premiumsupport/knowledge-center/dns-resolution-failures-ec2-linux/