Rails 在开发模式下不使用 nginx 提供资源
我在 Debian 6 中的虚拟机上工作。我前面有 nginx 来提供静态文件('jpg、png、css、js...)和 apache 来运行脚本。
但我有一个问题,我的资产文件出现 404 错误。
我的 nginx 配置:
server {
listen 80;
server_name mysite ;
#access_log /var/log/nginx/access.mysite.log;
#error_log /var/log/nginx/error.mysite.log;
# Les requêtes sont transmises au processus Apache écoutant en local sur le port 81
location / {
proxy_pass http://127.0.0.1:81/;
include /etc/nginx/proxy.conf;
}
# On remap sur la racine du domaine
if ($host != "mysite"){
rewrite ^(.*)$ http://mysite$1 permanent;
break;
}
# On distribue les fichiers statiques directement
location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|txt|srt|swf)$ {
root /home/php/mysite/public;
#access_log /var/log/nginx/access.mysite.log;
#error_log /var/log/nginx/error.mysite.log;
expires 1d;
}
}
和我的 apache 配置:
<VirtualHost *>
DocumentRoot /home/php/mysite/public
ServerName mysite
PassengerRoot /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.9
PassengerRuby /usr/local/bin/ruby
RailsEnv development
#ServerAlias
<Directory /home/php/mysite/public>
#Conf Standard
AllowOverride All
Order allow,deny
Allow from all
</Directory>
TransferLog /dev/null
</VirtualHost>
我的development.ru
MySite::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true
# Show full error reports and disable caching
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Don't care if the mailer can't send
config.action_mailer.raise_delivery_errors = false
# Print deprecation notices to the Rails logger
config.active_support.deprecation = :log
# Only use best-standards-support built into browsers
config.action_dispatch.best_standards_support = :builtin
# Do not compress assets
config.assets.compress = false
# Expands the lines which load the assets
config.assets.debug = true
end
我使用rails 3.1.1 和乘客。我认为这确实是一个 nginx 问题,因为当我访问 http://mysite:81 (直接在 apache 上)时,一切都会发生工作正常。
谢谢你的帮助。
I work on a virtual machine in Debian 6. I have nginx in front to serve statics files ('jpg,png,css,js...) and apache to run script.
But i have a problem, My assets files make a 404 error.
My nginx configuration :
server {
listen 80;
server_name mysite ;
#access_log /var/log/nginx/access.mysite.log;
#error_log /var/log/nginx/error.mysite.log;
# Les requêtes sont transmises au processus Apache écoutant en local sur le port 81
location / {
proxy_pass http://127.0.0.1:81/;
include /etc/nginx/proxy.conf;
}
# On remap sur la racine du domaine
if ($host != "mysite"){
rewrite ^(.*)$ http://mysite$1 permanent;
break;
}
# On distribue les fichiers statiques directement
location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|txt|srt|swf)$ {
root /home/php/mysite/public;
#access_log /var/log/nginx/access.mysite.log;
#error_log /var/log/nginx/error.mysite.log;
expires 1d;
}
}
And my apache configuration :
<VirtualHost *>
DocumentRoot /home/php/mysite/public
ServerName mysite
PassengerRoot /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.9
PassengerRuby /usr/local/bin/ruby
RailsEnv development
#ServerAlias
<Directory /home/php/mysite/public>
#Conf Standard
AllowOverride All
Order allow,deny
Allow from all
</Directory>
TransferLog /dev/null
</VirtualHost>
My development.ru
MySite::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true
# Show full error reports and disable caching
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Don't care if the mailer can't send
config.action_mailer.raise_delivery_errors = false
# Print deprecation notices to the Rails logger
config.active_support.deprecation = :log
# Only use best-standards-support built into browsers
config.action_dispatch.best_standards_support = :builtin
# Do not compress assets
config.assets.compress = false
# Expands the lines which load the assets
config.assets.debug = true
end
I use rails 3.1.1 with passenger. I thin it's really a nginx problem because when i go to http://mysite:81 (so on apache directly), everything work fine.
Thank you for help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的问题是在我的 nginx 配置中,
所以我将其删除,它禁用 nginx 提供静态文件,但在开发模式下它不是很有用。
谢谢你的帮助。
My problem was about this in my nginx configuration
So i remove it, it disables nginx to serve static file but it's not very usefull in development mode.
Thank you for help.