Ask A Question

Notifications

You’re not receiving notifications from this thread.

Links not working on production server

Edward Bishop asked in Servers

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.

Reply

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.

Reply

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?

Reply

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.

Reply

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}

Reply

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.

Reply

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.

Reply

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.

Reply

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!!

Reply

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.

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 87,265+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.