Skip to main content

Links not working on production server

Servers • Asked by Edward Bishop

I'm at a loss. After finally successfully deploying using Capistrano, and finally figuring out why my assets were missing, I have another issue. I have a link that point to static pages (contact) generated via a static_pages controller. Locally, the app works fine and I can visit the page but on production, I get a 404. I cannot find anything on SO on why this is happening and I'm lost. Any ideas? I followed the GoRails Deploy guide.


Got some links or code we can take a look at? I bet it's something pretty simple but one of those differences when deploying to production.


Hi Chris,

Here is the link to the website. http://198.199.98.206/

Everything works perfect locally but breaks in production. The only link that works is root. Everything else gives a 404

Nginx config
server {
# listen 80 default_server;
# listen [::]:80 default_server ipv6only=on;

    server_name 198.199.98.206;
    passenger_enabled on;
    passenger_app_env production;
    root /home/deploy/resume/current/public;
    index index.html index.htm;

    # Make site accessible from http://localhost/
    # server_name localhost;

    location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            try_files $uri $uri/ =404;
            # Uncomment to enable naxsi on this location
            # include /etc/nginx/naxsi.rules
    }

What else would you like to have a look at?


Ah! This makes much more sense. It's not Rails, but your nginx config that's wrong. I was a bit confused how Rails wouldn't be responding to those properly.

You might try simplifying your config there to this and seeing what happens:

server {
  listen 80 default_server;
  server_name 198.199.98.206;
  passenger_enabled on;
  passenger_app_env development;
  root /home/deploy/resume/current/public;
}

See if that helps at all, if not there are a few other things we can check.


I'm thinking it has something to do with Nginx and not my rails app. I edited the config and changed the env to development and I get a migration error. I'm guessing I should redeploy the app in development?

Here is my deploy/production.rb
set :stage, :production
server '198.199.98.206', user: 'deploy', roles: %w{web app db}


Alright! Now we're onto something. I think what happened the first time was that Passenger wasn't actually serving up the homepage through Rails and instead it was just serving up a static file instead directly. This is good.

So now your database migrations need to be run on your server which you can do with cap deploy:migrate

Once that is done, then I think Rails should successfully boot and serve up your pages.


Tried cap deploy:migrate and get the following error.

/Users/ebishop/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/capistrano-3.1.0/lib/capistrano/i18n.rb:4: warning: duplicated key at line 6 ignored: :starting
Stage not set, please call something such as cap production deploy, where production is a stage you have defined.

Tried 'cap production deploy:migrate' and it runs but the same error is displayed on the website.


Here's a question: do you have database migrations in your app?

Also this error is saying development and you probably want production. My mistake on that nginx snippet. You'll want to update that to say production instead. This might be the cause of why nothing ran.

When you run the migrations with capistrano, you should see the migrations printed out in the logs when it works correctly.


Success! Everything works! I'm thinking it had something to do with the listen on port 80 since its now uncommented.

Chris, thank you! Its been days of trying to deploy this!!


Congrats!! Glad you got it working even if it did take a few days ;-)

The first few setups I had with nginx had a bunch of the same problems. Eventually you start to realize what works and troubleshooting gets a lot easier. There are just so many moving parts, it can be hard to figure out where things are going wrong at the beginning.


Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 27,623+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.