Hide Headers in Passenger/Nginx Server - ruby-on-rails

I am trying to hide this headers for the production server but without success :
X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 3.0.7
X-Runtime: 0.021429
Server: nginx/1.0.0 + Phusion Passenger 3.0.7 (mod_rails/mod_rack)
Using :
- Rails 3.0.9
- Passenger 3.0.7
- Nginx 1.0.0
Any ideas ?

To remove nginx Server: header you could use server_tokens off directive.
For other headers try using Headers More nginx module:
more_set_headers 'Server: anon'; # replace the default 'nginx + Passenger'
more_set_headers 'X-Powered-By'; # clear header entirely

It possible to hide passenger headers, but require specific configuration. Something like this should work:
External world faced part:
upstream x {
server your-server:8040;
}
server {
server_name your-domain;
# ...
location / {
# ...
proxy_hide_header X-Powered-By;
proxy_hide_header X-Runtime;
proxy_pass http://x;
}
}
Passenger powered site:
server {
server_name local-site;
listen 8040 default_server;
location / {
passenger_enabled on;
# regular site configuration
}
}
local-site can be on same nginx with your-domain part, but this, probably, slight slow down request handling.

Related

Delete server header from response

Env :- Rails 3.2 , Ruby-2.1.1p76
Server: nginx/1.8.0 + Phusion Passenger 4.0.59
X-Powered-By: Phusion Passenger 4.0.59
I want to remove these 2 headers from response. I know I can edit my nginx config and set server_tokens to off but is there any way I can handle this in codebase?
For that, There is a module named headers more. You need to compile it as dynamic/static module with Nginx.
Then you can add/remove/modify headers via following syntax in your server blocks:
Add/Edit Header:
more_set_headers "Server: Your_prefered_name";
Delete Header:
more_clear_headers "Server";
I use this two options in nginx config-file:
passenger_show_version_in_header off;
server_tokens off;
This isn't remove server-strings from headers, but at least don't show versions:
Server: nginx + Phusion Passenger
X-Powered-By: Phusion Passenger

nginx with passenger don't handle static assets

I have rails app running with helpfull nginx and passenger, and I want to add static page (conteins code coverage analysis tool - simplecov).
Localy this works fine (without passenger), but on the server this don't works.
My nginx.conf:
#user nobody;
worker_processes 1;
events {
worker_connections 1024;
#speed up for linux 2.6+
use epoll;
}
http {
passenger_root /home/demo/.rvm/gems/ruby-1.9.3-p0#gm/gems/passenger-3.0.9;
passenger_ruby /home/demo/.rvm/wrappers/ruby-1.9.3-p0#gm/ruby;
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name *.dev.mysite.com;
root /var/www/projects/mysite/qa/current/public;
passenger_enabled on;
rails_env qa;
charset utf-8;
error_log /var/www/projects/mysite/qa/shared/log/host.error.log;
}
#Coverage code tool (SimpleCov gem)
server {
listen 4444;
server_name coverage.mysite.com;
location / {
root /var/lib/jenkins/jobs/WebForms/workspace/coverage;
index index.html index.htm;
}
}
#Yard server
server {
listen 5555;
server_name yard.mysite.com;
location / {
proxy_pass http://127.0.0.1:8808;
}}}
And nothing receive when I try to hit to coverage.mysite.com:4444.
I think I remember coming across something similar to this on one of my rails apps.
Have you tried commenting and uncommenting the lines below?:
# in config/environments/production.rb
# Specifies the header that your server uses for sending files
#config.action_dispatch.x_sendfile_header = "X-Sendfile"
# For nginx:
config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
It should be near the top, around line 12 through 16.
Try that, then redploy and test in the browser.

Nginx doesn't recognize my Rails 3 application

I have set up nginx + REE + passenger on my Linode VPS, which has been running great for past six month, both for Rails 2.3.x and Sinatra applications.
However this week I tried to add Rails 3 application to the stack, and I keep on getting 404 Not Found. Logs show that nginx doesn't recognize Rails application and is trying to serve it as static.
2010/11/29 23:44:44 [error] 12464#0: *29 "/var/app/modelky/public/index.html"
is not found (2: No such file or directory), client: 90.177.23.122, server:
reedink.com, request: "GET / HTTP/1.1", host: "reedink.com"
2010/11/29 23:44:44 [error] 12464#0: *30 open() "/var/app/modelky/public/favicon.ico"
failed (2: No such file or directory), client: 90.177.23.122,
server: reedink.com, request: "GET /favicon.ico HTTP/1.1", host: "reedink.com"
However, I'm using the same configuration as I use for all my other Rails 2.3.5 and Sinatra applications that works without any problems
server {
listen 80;
server_name www.reedink.com;
rewrite ^(.*) http://reedink.com$1 permanent;
}
server {
listen 80;
server_name reedink.com;
root /var/app/modelky/public;
passenger_enabled on;
}
From what I understand, Rails 3 should be rack compatible, so from the server's point of view, it's no different than any Sinatra application right?
I just built out a rail 3 box on linode this weekend. I started w/ this stackscript
http://www.linode.com/stackscripts/view/?StackScriptID=1288
and then went from there.
here's a copy of my server conf from the nginx.conf
server {
listen 80;
server_name localhost;
root /home/deploy/foo.bar.com/current/public;
passenger_enabled on;
}
i'd also try adding a static index.html file, get nginx working properly and then try and bootstrap the rails app.
Looks like your request is not hitting Rails. I would try to:
put a static index.html in /var/app/modelky/public to see if it shows up
check if the Rails app is in the given path and restart nginx
prestart Passenger on that server and see how it reacts
To prestart Passenger:
http {
server {
listen 80;
server_name www.reedink.com;
rewrite ^(.*) http://reedink.com$1 permanent;
}
server {
listen 80;
server_name reedink.com;
root /var/app/modelky/public;
passenger_enabled on;
}
passenger_pre_start http://reedink.com/;
}

How do I configure nginx to have a Rails app at a domain and WordPress at /blog/?

I've got a Rails app deployed via nginx/passenger. It will have multiple domains pointing to it.
I'm wondering if it's possible to configure nginx so that any URL that matches [somedomain.com]/blog/ will be servered by PHP/WordPress located in a different directory.
So, for example:
domain1.com, domain2.com, & domain2.com/some-resource/1 point to the Rails app at /var/rails/mainapp/
but domain1.com/blog/ goes to /var/sites/domain1.com/
and domain2.com/blog/ goes to /var/sites/domain2.com/
server {
location /blog {
alias /var/sites/domain1.com/;
}
location / {
}
}
You need define you /blog before / location
Here is my config. Hope it helps someone.
# Redirect all requests containing 'www.your-website.ru'
# to 'your-website.ru'
server {
listen 80;
server_name www.your-website.ru;
rewrite ^(.*) http://your-website.ru$1 permanent;
}
server {
listen 80;
server_name your-website.ru;
access_log logs/your-website.ru.log;
root /path-to-your-website.ru/current/public;
#####################
# Rails
#####################
location / {
rails_env production; # this is a production server
passenger_enabled on; #

nginx rewrite rules with Passenger

I'm trying to migrate to nginx from Apache using Passenger in both instances to host a Rails app. The app takes a request, which is for an image- if the image exists at /system/logos/$requestedimage then it should get served, or it should be allowed to hit the Rails app to generate it if needed (where it is then cached to /system/logos).
In Apache I used the following:
RewriteCond %{DOCUMENT_ROOT}/system/logos/%{REQUEST_FILENAME} -f
RewriteRule ^/(.*)$ http://assets.clg.eve-metrics.com/system/logos/$1
This worked fine. The assets. subdomain is another subdomain but with the same root, just Passenger disabled, specifically set up for hosting static files (expires-wise).
In nginx I am using the following:
server {
listen 80;
passenger_enabled on;
server_name clg.eve-metrics.com www.clg.eve-metrics.com;
root /opt/www/clg/current/public;
gzip on;
gzip_min_length 1000;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain application/xml text/css application/javascript;
gzip_disable msie6;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
if (-f $document_root/system/logos$request_filename) {
rewrite ^/(.*)$ http://assets.clg.eve-metrics.com/system/logos/$1 break;
}
}
This doesn't work so well. At all, in fact. It never redirects to the cached path and it never hits the Rails app. It's like nginx is assuming it's a static asset so not passing it on to Passenger. Is there a way to stop this behaviour so it hits the app?
My rails application is running on nginx and passenger. I have moved my rails cache directory from the default /public to /public/system/cache/. To make it work, I had to insert this into my vhost config file:
if (-f $document_root/system/cache/$uri/index.html) {
rewrite (.*) /system/cache/$1/index.html break;
}
if (-f $document_root/system/cache/$uri.html) {
rewrite (.*) /system/cache/$1.html break;
}
I remember that I too tried to make it work with $request_filename, but didn't get it to work. Try with $uri instead and see if it works :-)
James, please try this configuration file
https://gist.github.com/711913
and pay attention on this location config:
location ~* \.(png|gif|jpg|jpeg|css|js|swf|ico)(\?[0-9]+)?$ {
access_log off;
expires max;
add_header Cache-Control public;
}
passenger won't let Rails to manage your assets files if you have right permissions (user run nginx should has permissions to access to file directly)

Resources