1

Veran estoy intentando usar este builpack para poder utilizar NGINX en mi aplicación de heroku, pero no se mucho sobre como configurar nginx. Y solo me base en algunos ejemplos pero no me funciona el archivo nginx.conf.erb correctamente.

Recientemente modifique mi archivo nginx.conf.erb y ahora me muestra el error 404 y me nuestra la pagina de error de heroku no such app.

Este es mi archivo nginx.conf.erb

daemon off;
#Heroku dynos have at least 4 cores.
worker_processes <%= ENV['NGINX_WORKERS'] || 8 %>;

events {
    use epoll;
    multi_accept on;
    accept_mutex on;
    worker_connections <%= ENV['NGINX_WORKER_CONNECTIONS'] || 10000 %>;
}

http {
    charset utf-8;
    gzip on;
    gzip_comp_level 9;
    gzip_min_length 512;
    gzip_vary on;
    gzip_buffers 16 8k;
    gzip_proxied any;
    gzip_types
        application/atom+xml
        application/javascript
        application/x-javascript
        application/json
        application/rss+xml
        application/xml+rss
        application/vnd.ms-fontobject
        application/x-font-ttf
        application/x-web-app-manifest+json
        application/xhtml+xml
        application/xml
        font/opentype
        image/svg+xml
        image/x-icon
        text/css
        text/plain
        text/javascript
        text/x-component;
    gzip_disable "MSIE [1-6]\.";

    server_tokens off;

    client_body_buffer_size 128k;
    client_header_buffer_size 1k;
    large_client_header_buffers 4 8k;
    output_buffers 1 32k;
    postpone_output 1460;

    log_format l2met 'measure#nginx.service=$request_time request_id=$http_x_request_id';
    access_log <%= ENV['NGINX_ACCESS_LOG_PATH'] || 'logs/nginx/access.log' %> l2met;
    error_log <%= ENV['NGINX_ERROR_LOG_PATH'] || 'logs/nginx/error.log' %>;
    log_not_found on;

    include mime.types;
    default_type application/octet-stream;
    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    types_hash_max_size 2048;
    client_max_body_size 20M;

    #Must read the body in 5 seconds.
    client_body_timeout 5;

    resolver 1.1.1.1 1.0.0.1 8.8.8.8 8.8.4.4 208.67.222.222 208.67.220.220 valid=60s;
    resolver_timeout 2s;

    upstream app_server {
        server nginxapp.herokuapp.com:443;
        server 127.0.0.1:<%= ENV["PORT"] %> backup;
    }
    proxy_ssl_server_name on;
    proxy_cache_path /tmp/nginx levels=1:2 keys_zone=nginxapp:10m inactive=60m;
    proxy_cache_key "$scheme$request_method$host$request_uri";

    server {
        gzip on;
        gzip_comp_level 9;
        gzip_min_length 512;
        gzip_vary on;
        gzip_buffers 16 8k;
        gzip_proxied any;
        gzip_disable "MSIE [1-6]\.";
        listen <%= ENV["PORT"] %>;
        server_name _;
        keepalive_timeout 65;
        keepalive_requests 100000;
        charset utf-8;

        root /public;

        location / {
            set $upstream_app app_server;
            proxy_cache nginxapp;
            proxy_http_version 1.1;
            proxy_cache_bypass $http_cache_control;
            add_header X-Proxy-Cache $upstream_cache_status;
            proxy_ssl_name nginxapp.herokuapp.com;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Host $host;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_set_header Host $host;
            proxy_redirect off;
            proxy_pass https://$upstream_app;
        }

        location = /favicon.ico {
            log_not_found off;
            access_log off;
        }

        location = /robots.txt {
            log_not_found off;
            access_log off;
        }

        location ~* \.(?:css(\.map)?|js(\.map)?|jpe?g|png|gif|ico|cur|heic|webp|tiff?|mp3|m4a|aac|ogg|midi?|wav|mp4|mov|webm|mpe?g|avi|ogv|flv|wmv)$ {
            expires 1y;
            access_log off;
        }

        location ~* \.(?:svgz?|ttf|ttc|otf|eot|woff2?)$ {
            add_header Access-Control-Allow-Origin "*";
            expires 1y;
            access_log off;
        }
    }
}

Y este es mi archivo Procfile para heroku

web: start-nginx-solo node app.js
5
  • Lograste resolverlo? Estoy intentando hacer lo mismo Commented el 5 jul. 2020 a las 1:23
  • @ArthuroAli si lo resolví, solo que olvide auto responder mi pregunta xd Commented el 5 jul. 2020 a las 9:20
  • Recuerdas como o tienes la config? Commented el 5 jul. 2020 a las 16:42
  • @ArthuroAli Si, deja auto respondo mi pregunta para que la copees y modifiques con tu app de heroku Commented el 5 jul. 2020 a las 18:19
  • @ArthuroAli te recomiendo que la configuración que deje ahí en mi respuesta la dejes tal cual, o por lo menos no modifiques el listen <%= ENV['PORT'] %> Commented el 5 jul. 2020 a las 18:41

1 respuesta 1

1

Había olvidado auto responder mi pregunta después de un tiempo de haber resuelto mi problema xd

Lo resolví de la siguiente manera(soy un poco malo explicando así que solo dejare la configuración de nginx)

daemon off;

worker_processes 8;

events {
    use epoll;
    multi_accept on;
    accept_mutex on;
    worker_connections 10000;
}

http {
    charset utf-8;
    gzip on;
    gzip_comp_level 9;
    gzip_min_length 512;
    gzip_vary on;
    gzip_buffers 16 8k;
    gzip_proxied any;
    gzip_types
    application/atom+xml
    application/javascript
    application/x-javascript
    application/json
    application/rss+xml
    application/xml+rss
    application/vnd.ms-fontobject
    application/x-font-ttf
    application/x-web-app-manifest+json
    application/xhtml+xml
    application/xml
    font/opentype
    image/svg+xml
    image/x-icon
    text/css
    text/plain
    text/javascript
    text/x-component;
    gzip_disable "MSIE [1-6]\.";

    server_tokens off;

    client_body_buffer_size 128k;
    client_header_buffer_size 1k;
    large_client_header_buffers 4 32k;
    output_buffers 1 32k;
    postpone_output 1460;
    
        uuid4 $uuid;
    
    log_format l2met 'measure#nginx.service server=nginx method=$request_method path=$uri host=$host request_id=$uuid fwd=$proxy_add_x_forwarded_for dyno=web.<%= ENV['WEB_CONCURRENCY'] %> connect=$upstream_connect_time service=$upstream_response_time status=$status bytes=$bytes_sent protocol=$scheme';
    access_log logs/nginx/access.log l2met;
    error_log logs/nginx/error.log;
    log_not_found off;

    include mime.types;
    default_type application/octet-stream;
    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    types_hash_max_size 2048;
    client_max_body_size 20M;

    client_body_timeout 5;

    resolver 1.1.1.1 1.0.0.1 8.8.8.8 8.8.4.4 208.67.222.222 208.67.220.220 valid=60s;
    resolver_timeout 2s;

    upstream app_server {;
        server 127.0.0.1:8080;
    }
    #proxy_ssl_server_name on;
    proxy_cache_path /tmp/nginx levels=1:2 keys_zone=herokuapp:10m inactive=60m;
    proxy_cache_key "$scheme$request_method$host$request_uri";


    map $status $condition {
        ~^[23] 0;
        default 1;
    }

    server {
        gzip on;
        gzip_comp_level 9;
        gzip_min_length 512;
        gzip_vary on;
        gzip_buffers 16 8k;
        gzip_proxied any;
        gzip_types
        application/atom+xml
        application/javascript
        application/x-javascript
        application/json
        application/rss+xml
        application/xml+rss
        application/vnd.ms-fontobject
        application/x-font-ttf
        application/x-web-app-manifest+json
        application/xhtml+xml
        application/xml
        font/opentype
        image/svg+xml
        image/x-icon
        text/css
        text/plain
        text/javascript
        text/x-component;
        gzip_disable "MSIE [1-6]\.";

        listen <%= ENV['PORT'] %>;
        listen [::]:<%= ENV['PORT'] %>;
        server_name _;
        keepalive_timeout 65;
        keepalive_requests 100000;
        charset utf-8;

        root /public;

        location ~* / {
            set $app_server app_server;
            proxy_cache herokuapp;
            proxy_http_version 1.1;
            proxy_cache_bypass $http_update;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_set_header X-Forwarded-Host $host;
            proxy_set_header X-Forwarded-Port $server_port;
            proxy_set_header X-Forwarded-Start $upstream_connect_time;
            proxy_set_header X-Request-ID $request_id;
            #proxy_set_header Upgrade $http_upgrade;
            #proxy_set_header Connection "upgrade";
            proxy_set_header Via $http_via;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header Host $host;
            #proxy_ssl_name $host;
            #proxy_ssl_verify off;
            proxy_buffering off;
            proxy_pass http://$app_server$request_uri;
            proxy_redirect off;
        }

        location = /favicon.ico {
            log_not_found off;
            access_log off;
        }

        location = /robots.txt {
            log_not_found off;
            access_log off;
        }

        location ~* \.(?:css(\.map)?|js(\.map)?|jpe?g|png|gif|ico|cur|heic|webp|tiff?|mp3|m4a|aac|ogg|midi?|wav|mp4|mov|webm|mpe?g|avi|ogv|flv|wmv)$ {
            expires 1y;
            access_log off;
        }

        location ~* \.(?:svgz?|ttf|ttc|otf|eot|woff2?)$ {
            add_header Access-Control-Allow-Origin "*";
            expires 1y;
            access_log off;
        }
        #       error_page 403 /html/403;
        #       error_page 404 /html/404;
        #       error_page 500 /html/500;
        #       error_page 502 /html/502;
        #       error_page 503 /html/503;
        #       error_page 504 /html/504;
    }
}

Lo que hice fue crear un localhost:8080 con NodeJS en heroku y pasárselo al upstream de nginx para que redireccionara al localhost:8080 de manera interna

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.