I run a rails app.
rails s -p 5000 -e production &
The website works fine.
But, when terminal (which runs above command) exits, the website only shows blank page.
When I open terminal again, the rails process is still running.
I check nginx log. After terminal exits, nginx seems stop talking rails. Nginx just returns HTTP 200.
Below is nginx config.
server {
listen 80;
server_name mydomain.org;
rails_env production;
root /home/user/website/public;
client_max_body_size 10M;
access_log /opt/nginx/logs/website.log;
error_log /opt/nginx/logs/website_err.log;
location / {
proxy_pass http://127.0.0.1:5000;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
I think you missing -d or --daemon option for run server as a daemon:
rails s -p 5000 -e production -d &
Related
i try redirect to proxy-server nginx.
location /phpmyadmin {
proxy_http_version 1.1;
proxy_pass https://${PMA}:5000/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
But i get error:
nginx: [emerg] invalid number of arguments in "proxy_set_header" directive in /etc/nginx/nginx.conf:26
full code for inspect error in this listing, because i'm real can't find some error's (${env} = correctry changing in script
user root;
worker_processes auto;
pcre_jit on;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
keepalive_timeout 3000;
sendfile on;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
server {
listen 443 ssl;
listen [::]:443 ssl;
ssl_certificate /etc/ssl/nginx.crt;
ssl_certificate_key /etc/ssl/nginx.key;
root /home;
index default.html /default.html;
location /phpmyadmin {
proxy_http_version 1.1;
proxy_pass https://${PMA}:5000/;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto https;
}
location /wordpress {
return 307 http://${WP}:5050/;
}
location / {
try_files /default.html default.html default.htm;
}
}
server {
listen 80;
listen [::]:80;
return 301 https://$host$request_uri;
}
}
daemon off;
how much simvols need for post)
I used envsubst for environment replacing, and this util tried swap $host and other nginx envs, solved with:
envsubst '\$WP \$PMA' < nginx.template.conf > nginx.ready.conf; rm nginx.template.conf
Expanding on the working answer from #mikhail-prigorodov:
The situation described by the OP arises when using the Nginx Docker container with Docker Compose. In the documentation, it reads:
Out-of-the-box, nginx doesn't support environment variables inside most configuration blocks. But this image has a function, which will extract environment variables before nginx starts.
So, if you are using environment variables in your docker-compose.yml as part of a 12-Factor App design, you have to figure out how to get them into your Nginx config file properly.
The solution in the Nginx Docker documentation is to run envsubst on a template configuration file and send the output to the Nginx config file. The Dockerfile syntax, which is mentioned in this GitHub issue is:
CMD envsubst < /etc/nginx/templates/default.conf.template > /etc/nginx/conf.d/default.conf && exec nginx -g 'daemon off;'
But that solution runs into a problem if you have Nginx-defined variables AND environment variable placeholders in your configuration template. In the directory where I'm building my Nginx container (where my Dockerfile is), I have a templates directory with a file called default.conf.template, as directed in the documentation. The file contains Nginx variables and environment variables. For example:
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
location /static {
alias /usr/share/nginx/html/${STATIC_DIR};
}
The problem (I think) is that envsubst is looking for the "$" character that marks the start of the environment variables. In any case, you'll find that after running envsubst successfully, each line in your new Nginx config file that has a Nginx-defined variable (leading "$") in the template gives an error when you try and start Nginx.
To solve this problem, use the syntax provided by #mikhail-prigorodov. Applied to my example:
CMD envsubst '\$STATIC_DIR' < /etc/nginx/templates/default.conf.template > /etc/nginx/conf.d/default.conf && exec nginx -g 'daemon off;'
This was the solution that worked for me after hours of frustration.
I am trying to setup a docker network of two containers. One container holds a Wildfly application, and the other machine is an Nginx proxy server. The proxy server is just a placeholder for a load balancer used in a production environment. Therefore, the Nginx server simply forwards all requests to the wildfly server on :8080.
This setup works when I run the containers in the default bridge network, but I would like to use a user-defined network to mimic hostname resolution. But when I run the setup in a user-defined network, I can no longer reach the Wildfly application through the Nginx server, and I only get 504 timeout errors.
This is my nginx configuration file:
server {
listen 80;
return 301 https://$host$request_uri;
}
server {
listen 443;
server_name dev-reports.passkey.com;
ssl_certificate /etc/nginx/cert.crt;
ssl_certificate_key /etc/nginx/cert.key;
ssl on;
ssl_session_cache builtin:1000 shared:SSL:10m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
ssl_prefer_server_ciphers on;
access_log /var/log/nginx/rpt.access.log;
location / {
sub_filter '172.18.0.2' '127.0.0.2';
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# Fix the “It appears that your reverse proxy set up is broken" error.
proxy_pass http://172.18.0.2:8080;
proxy_connect_timeout 900;
proxy_send_timeout 900;
proxy_read_timeout 900;
send_timeout 900;
}
}
And these are the scripts I use to run the Nginx server:
IP=127.0.0.3
docker run -d --name nginx-server -v ~/path/to/logs:/var/log/nginx --network user-network -p $IP:8443:443 nginx
And the Wildfly server:
IP=127.0.0.2
docker run -d --name wildfly-app --network user-network -v $1:/mnt/share -v $1/logs:/opt/wildfly/standalone/log/ -p $IP:9990:9990 -p $IP:80:8080 -p $IP:8787:8787 -p $IP:443:8443 -p $IP:1099:1099 -p $IP:1129:1129 -p $IP:1139:1139 -p $IP:8083:8083 -p $IP:8889:8889 wildfly-app
I run sudo ifconfig lo0 alias 127.0.0.* up To open up 127.0.0.2 and 127.0.0.3
I have a local Nginx installation that uses a custom config file to route different services and a web application to a single port.
The Nginx configuration file looks something like:
server {
listen 8080;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
location /api/login {
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server %host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost:8181;
client_max_body_size 10M;
}
location /api/accountopening {
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server %host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost:8282;
client_max_body_size 10M;
}
...
I am trying to do the same thing with Docker and the Nginx official image in DockerHub, but I haven't been able to. In their documentation they say I should do something like:
docker run --name cor-nginx \
-v ~/dev/nginx/conf/nginx.conf:/etc/nginx/nginx.conf:ro \
-d \
-p 8080:80 nginx
to create a volume and specify a custom config file but no results so far.
Has anyone done anything similar ?
Thanks a lot in advance!
Please exec to your Nginx container and check if a path to configuration files is valid.
I think you pass the wrong path, default it is: /etc/nginx/conf.d.
Also, you should use Dockerfile to build your changed image, it's better and more clarify than passing options as an argument to Docker.
You should also delete existing - default Nginx configurations.
I think it will be so helpful for you:
how to run nginx docker container with custom config?
So I tried to set up a rails app using Bryan Bate's private_pub gem (a wrapper for the faye gem) to create chat channels. It works great on my local machine in dev mode.
I'm also booting up the private_pub server on port 8080 at the same time my rails app starts by including a initializer file with the lines:
Thread.new do
system("rackup private_pub.ru -s thin -E production -p 8080")
end
however, after deploying to aws ec2 ubuntu instance with the nginx webserver and puma app sever, the chrome console keeps showing this every 2 seconds, and the real time chat features don't work.
GET http://localhost:8080/faye.js net::ERR_CONNECTION_REFUSED
If I open port 8080 in my aws security group, I can see the big chunk of javascript code in faye.js using curl from localhost:8080/faye.js when I ssh into the instance. I can also access it from my browser if I go to http://my.apps.public.ip:8080/faye.js. I can't access it if I remove 8080 from the security group, so I don't think this is an firewall problem.
Also, if I change the address from localhost to 0.0.0.0 or the public ip for my ec2 instance, the chrome console error is gone, but the real time chat is still not working.
I suspect I might have to do more configuration to nginx because all I have done so far to configure the nginx server is in /etc/nginx/sites-available/default, I have:
upstream app {
server unix:/home/deploy/myappname/shared/tmp/sockets/puma.sock fail_timeout=0;
}
server {
listen 80;
server_name localhost;
root /home/deploy/myappname/public;
try_files $uri/index.html $uri #app;
location / {
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Connection '';
proxy_pass http://app;
}
location ~ ^/(assets|fonts|system)/|favicon.ico|robots.txt {
gzip_static on;
expires max;
add_header Cache-Control public;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}
But maybe this has nothing to do with nginx either, I'm pretty lost. Has anyone experienced this or could suggest an alternative solution? I could post any additional config files here if needed.
Solved
first I took Ian's advice and set server_name to my public ip
then
based on guide from http://www.johng.co.uk/2014/02/18/running-faye-on-port-80/
I added the location block
location ^~ /faye {
proxy_pass http://127.0.0.1:9292/faye;
proxy_redirect off;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_http_version 1.1;
proxy_buffering off;
proxy_cache_bypass $http_pragma $http_authorization;
proxy_no_cache $http_pragma $http_authorization;
}
finally, for my private_pub.yml I set the faye entry point for production:
production:
server: "http://my.public.ip:80/faye/faye"
secret_token: "mysecrettoken"
signature_expiration: 3600 # one hour
and now the chatting in my app responds much faster than when I was using the remote standalone chat server I put on on heroku because both the chat server and my main app is running in the same instance.
I checked the config syntax by run nginx -t then get the results:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
But when I run service nginx restart goes fail.
I have a config file named a.com in the sites-enabled folder, here's the content:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
server_name a.com;
# root /usr/share/nginx/html;
# index index.html index.htm;
root /home/a/public;
client_max_body_size 10G;
location / {
proxy_pass http://localhost:3000;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_buffering off;
}
}
I'm at Ubuntu 14.10 and want to deploy a rails server.
I kill the nginx's process manually, then start nginx again, solved the problem.
I had this issue and using sudo solved it:
sudo service nginx restart
It might help to enable logs to checks the errors:
https://www.nginx.com/resources/admin-guide/logging-and-monitoring/