Frequently asked questions about Ubuntu+rails+passenger+apache+nginx

Source: Internet
Author: User
Tags socket

The title of many questions is the error message recorded in the log after an error.

Apache logs are in the/var/log/apache2/directory, Error.log. Of course, there may also be other locations. If you are downloading httpd, compile the installation, it is possible in the/usr/local/apache directory.

Nginx's log in the/opt/nginx/log/, is also error.log. It is also possible in other locations, such as the installation directory or the/var/log/nginx/.

1.rails 3.1.0 actionview::template::errror (application.css isn ' t precompiled)

Answer:

This error occurs in a production environment where the production environment requires assets to be precompiled or set to compile at run time.

Set up configuration information for the production environment.

# config/environments/production.rb ... 
Config.assets.compile = True
...

or the execution

Bundle EXEC Rake Assets:precompile

Then restart the rails server, or restart Apache and Nginx.

Reference links

Http://stackoverflow.com/questions/7275636/rails-3-1-0-actionviewtemplateerrror-application-css-isnt-precompiled

http://ruby-china.org/topics/1415

2. Install passenger

Gem Install passenger

Passenger-install-apache2-module

Passenger-install-nginx-module

The installation of the process will be prompted, you do not install the components, and so you have installed, passenger in the Apache and Nginx modules can be successfully installed. After installation, you will also be prompted how to set up Apache and Nginx.

3.Rails application Unable to connect to MySQL, Can ' t connect to the local MySQL server through socket '/tmp/mysql.sock ' (2) ( Mysql2::error)

/tmp/mysql.sock, you're in the Config/database.yml file.

Production: 
  adapter:mysql2 
  encoding:utf8 host:localhost database:blog pool:5 username 
  : Root 
  password:123.com 
  socket:/tmp/mysql.sock 
  timeout:5000

This means that the/tmp/mysql.sock file does not exist, in fact, is the wrong position.

After installing MySQL, locate the file in the following way.

Mysqladmin-u Root-p Variables | grep socket

After you enter a password, the contents of the face appear

root@web:/home/github/blog# mysqladmin-u root-p Variables |grep sock 
Enter password:  
| socket                                            |/var/run/ Mysqld/mysqld.sock                                                                                            | 
root@web:/home/github/blog#

The red content above can be filled into the Database.yml file, or create a symbolic link.

Ln-s/var/run/mysqld/mysqld.sock/tmp/mysql.sock

can also solve this problem.

4. How to set up rails_env in Apache configuration file in Apache for deployment to production environment

You can add parameters to the Rails server command to specify what configuration the service starts, the production environment, or the development environment.

Rails Server--environment=production

When data is migration, you can also specify which of the environments in the DATABASE.YML, the production environment, or the development environment.

Rake Db:create rails_env=production

<virtualhost *:80> 
  ServerName www.yourdomain.com 
  documentroot/var/www/yourfolder/public
  < Directory/var/www/yourfolder/public> 
    allowoverride all 
    options-multiviews 
    railsenv Development 
  </Directory> 
     
  Errorlog/var/log/apache2/yourdomain.error.log 
  loglevel warn 
  customlog/var/log/apache2/ Yourdomain.access.log combined 
</VirtualHost>

More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/Servers/web/

5. How to set up a rails_env in a nginx configuration file for Nginx deployed to a production environment

server {
Listen 80;
server_name www.yourhost.com;
Root/somewhere/public; # <---Be sure to the ' public '!
Passenger_enabled on;
RAILS_ENV Development; Nginx's passenger module defaults to the production mode, if it is developed on this machine
}

6.nginx of COMMON commands

Start Nginx

/usr/local/webserver/nginx/sbin/ngint–t Test configuration file is correct
/usr/local/webserver/nginx/sbin/ngint start

Reload configuration file

/usr/local/webserver/nginx/sbin/ngint–s Reload

Stop Nginx

/usr/local/webserver/nginx/sbin/ngint–s stop

7.passenger+nginx, start nginx always error, can't find Passenger_root

I was installing the nginx1.3.7 first, then installing the passenger, and this error occurred when I started it.

But when I install Passenger-install-nginx-module, I choose to let passenger download the nginx1.2, and then automatically compile the installation, the start of the time there is no problem.

I guess the latest version of Nginx and passenger have some compatibility issues.

8.mysql2

The MySQL adapter used by RAILS3 is MYSQL2. May need to be installed separately.

Gem Install Activerecord-mysql2-adapter

Bundle Install

9. After publishing to the production environment found that the modified App/views/layouts/application.html.erb, refresh the page, but did not change.

Using passenger, publish to production environment, use production environment configuration file config/environments/production.rb, there is a sentence in the file.

# Code is not reloaded between requests

Config.cache_class = true;

is to cache the code and not reload the code on multiple requests, all without seeing the effect after the update. Of course, the code published to the production environment are strictly tested, stable code, will not be modified to modify the things to go, changes will not require immediate results, the need to strictly test the line.

If this is required, you can change the setting to False. If you do not want to, you can also create a restart.txt file under TMP.

Touch Tmp/restart.txt

When you need to reload, modify the file access time.

echo "Hello" >> restart

You can also implement a reload without disrupting the configuration file for the production environment.

10.rails actionview::template::error (undefined method ' Post_comments_path '

Feature is to add a comment on the browsing page of a blog.

The add comment part of the form was added to the App/views/posts/show.html.erb, but was not added to the CONFIG/ROUTE.RB

Resources posts doing
     
  comments end 
     

11.nomethoderror:undefined method ' Has_attached_file '

You'll also need to add the following to your Gemfile

Gem "Paperclip",: Git => "Http://github.com/thoughtbot/paperclip.git"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.