Instantly share code, notes, and snippets.

Embed
What would you like to do?
# This is to enable WS support. Credits: # https://gist.github.com/Bubelbub/0a942a0d51a3d329897d
# THIS WORKS! for running the example 5.0.0.beta1 chat app on a single instance Elastic beanstalk AWS instance
files:
"/etc/nginx/conf.d/websockets.conf" :
content: |
upstream backend {
server unix:///var/run/puma/my_app.sock;
}
server {
listen 80;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
server_name env1.t3tiiauce6.us-west-2.elasticbeanstalk.com
# prevents 502 bad gateway error
large_client_header_buffers 8 32k;
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;
# prevents 502 bad gateway error
proxy_buffers 8 32k;
proxy_buffer_size 64k;
proxy_pass http://backend;
proxy_redirect off;
location /assets {
root /var/app/current/public;
}
# enables WS support
location /cable {
proxy_pass http://backend;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
}
container_commands:
01restart_nginx:
command: "service nginx restart"
@romankovt

This comment has been minimized.

Show comment
Hide comment
@romankovt

romankovt Apr 24, 2016

now you might need to set server_names_hash_bucket_size 128; if your server name URL is really long

romankovt commented Apr 24, 2016

now you might need to set server_names_hash_bucket_size 128; if your server name URL is really long

@Ravenclaw968

This comment has been minimized.

Show comment
Hide comment
@Ravenclaw968

Ravenclaw968 Mar 21, 2017

Does anyone know how to fix this error I get when I do "eb deploy"

Creating application version archive "app-69d3-170321_224137". Uploading: [##################################################] 100% Done... INFO: Environment update is starting. INFO: Deploying new version to instance(s). ERROR: [Instance: i-0b90fe72a05f095c7] Command failed on instance. Return code: 6 Output: nginx: [warn] conflicting server name "localhost" on 0.0.0.0:80, ignored nginx: [emerg] could not build server_names_hash, you should increase server_names_hash_bucket_size: 64 nginx: configuration file /etc/nginx/nginx.conf test failed. container_command 01restart_nginx in .ebextensions/nginx_proxy.config failed. For more detail, check /var/log/eb-activity.log using console or EB CLI. INFO: Command execution completed on all instances. Summary: [Successful: 0, Failed: 1]. ERROR: Unsuccessful command execution on instance id(s) 'i-0b90fe72a05f095c7'. Aborting the operation. ERROR: Failed to deploy application.

Ravenclaw968 commented Mar 21, 2017

Does anyone know how to fix this error I get when I do "eb deploy"

Creating application version archive "app-69d3-170321_224137". Uploading: [##################################################] 100% Done... INFO: Environment update is starting. INFO: Deploying new version to instance(s). ERROR: [Instance: i-0b90fe72a05f095c7] Command failed on instance. Return code: 6 Output: nginx: [warn] conflicting server name "localhost" on 0.0.0.0:80, ignored nginx: [emerg] could not build server_names_hash, you should increase server_names_hash_bucket_size: 64 nginx: configuration file /etc/nginx/nginx.conf test failed. container_command 01restart_nginx in .ebextensions/nginx_proxy.config failed. For more detail, check /var/log/eb-activity.log using console or EB CLI. INFO: Command execution completed on all instances. Summary: [Successful: 0, Failed: 1]. ERROR: Unsuccessful command execution on instance id(s) 'i-0b90fe72a05f095c7'. Aborting the operation. ERROR: Failed to deploy application.

@jasmo2

This comment has been minimized.

Show comment
Hide comment
@jasmo2

jasmo2 Mar 31, 2017

@Ravenclaw968 I got the same issue; if you got the solution please let mi know

jasmo2 commented Mar 31, 2017

@Ravenclaw968 I got the same issue; if you got the solution please let mi know

@egoens

This comment has been minimized.

Show comment
Hide comment
@egoens

egoens Apr 1, 2017

Would the location /cable section need to change if the site is using https:? I've implemented these suggestions, but I still receive the following error in the console:

WebSocket connection to 'wss://subdomain.mywebsitedomain.org/cable' failed: Error during WebSocket handshake: Unexpected response code: 404

egoens commented Apr 1, 2017

Would the location /cable section need to change if the site is using https:? I've implemented these suggestions, but I still receive the following error in the console:

WebSocket connection to 'wss://subdomain.mywebsitedomain.org/cable' failed: Error during WebSocket handshake: Unexpected response code: 404

@LEEY19

This comment has been minimized.

Show comment
Hide comment
@LEEY19

LEEY19 Aug 12, 2017

@Ravenclaw968 @jasmo2 did you guys manage to solve the abovementioned problem in the end?

LEEY19 commented Aug 12, 2017

@Ravenclaw968 @jasmo2 did you guys manage to solve the abovementioned problem in the end?

@ismailakbudak

This comment has been minimized.

Show comment
Hide comment
@ismailakbudak

ismailakbudak Nov 30, 2017

is there a solution for eb deploy exception:

nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (2: No such file or directory)
2017/11/30 10:06:23 [emerg] 13178#0: open() "/var/log/nginx/error.log" failed (2: No such file or directory)
nginx: configuration file /etc/nginx/nginx.conf test failed.

ismailakbudak commented Nov 30, 2017

is there a solution for eb deploy exception:

nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (2: No such file or directory)
2017/11/30 10:06:23 [emerg] 13178#0: open() "/var/log/nginx/error.log" failed (2: No such file or directory)
nginx: configuration file /etc/nginx/nginx.conf test failed.
@imgarylai

This comment has been minimized.

Show comment
Hide comment
@imgarylai

imgarylai Feb 1, 2018

Did anyone use config.force_ssl = true in your production.rb? I use this nginx config with the setting. However, I keep getting 301 redirection.

imgarylai commented Feb 1, 2018

Did anyone use config.force_ssl = true in your production.rb? I use this nginx config with the setting. However, I keep getting 301 redirection.

@fadec

This comment has been minimized.

Show comment
Hide comment
@fadec

fadec Apr 6, 2018

In my experience config.force_ssl = true in Rails lead to a redirect loop for a proxy_pass http://.... I force ssl using nginx redirects.

fadec commented Apr 6, 2018

In my experience config.force_ssl = true in Rails lead to a redirect loop for a proxy_pass http://.... I force ssl using nginx redirects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment