By peter398761
I’ve been trying for a while to figure out how to get www.ourapp.com to redirect to ourapp.com. I found this Stackoverflow post, which seems very clear, but so far I haven’t been able to make it work: http://stackoverflow.com/questions/7947030/nginx-no-www-to-www-and-www-to-no-www
It’s a Rails app, and I recently realized there’s an nginx.conf file in the config directory that’s executed as part of the deploy script; previously I had been sshing into the server directory and modifying the file in etc/nginx/sites-enabled, but didn’t realize it was getting written over every time I deployed.
However, even modifying the file there still it hasn’t having any effect. Nginx.conf currently looks like this (as does the version on the server now, obviously):
upstream unicorn {
server unix:/tmp/unicorn.streamfeed.sock fail_timeout=0;
}
server {
server_name www.streamfeed.com;
return 301 http://streamfeed.com$request_uri;
}
server {
listen 80 default deferred;
server_name streamfeed.com;
root /home/deployer/apps/streamfeed/current/public;
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
try_files $uri/index.html $uri @unicorn;
location @unicorn {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://unicorn;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}
I’ve also tried the version suggested for https in that SO post (which some other people suggest for http as well), using rewrite ^(.*) http://domain.com$1 permanent, and that doesn’t do anything either - I can have two different sessions open on our site at streamfeed.com and www.streamfeed.com. I’ve been banging my head against the wall on this for a long time at this point…obviously i’m missing something, but I don’t know what it is - can anyone help?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Your config looks proper, I’m not sure what’s wrong here. Per Module ngx_http_core_module, listen does not accept a default option, but it does accept default_server, so try replacing listen 80 default deferred; with listen 80 default_server deferred; and then restarting nginx.
Do you have any other server blocks or files in /etc/nginx/sites-enabled?
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.