Ruby on rails Rails不在生产中为my robots.txt和sitemap.xml.gz提供服务

Ruby on rails Rails不在生产中为my robots.txt和sitemap.xml.gz提供服务,ruby-on-rails,nginx,Ruby On Rails,Nginx,虽然这些文件在开发阶段以及在我本地机器上的生产阶段都有提供,但这些文件并没有在现场生产中提供。我得到一个404未找到错误。其他一切都很好。这些文件位于应用程序的公用目录(-approt-/public)中 我正在通过实时服务器使用nginx和unicorn。我的nginx/sites available/default文件: upstream example.com { server unix:/tmp/example.socket fail_timeout=0; } server {

虽然这些文件在开发阶段以及在我本地机器上的生产阶段都有提供,但这些文件并没有在现场生产中提供。我得到一个404未找到错误。其他一切都很好。这些文件位于应用程序的公用目录(-approt-/public)中

我正在通过实时服务器使用
nginx
unicorn
。我的
nginx/sites available/default
文件:

upstream example.com {
 server unix:/tmp/example.socket fail_timeout=0;
}

server {
  listen 80 default;
  server_name example.com www.example.com;
  root /home/myuser/apps/example/current/public;
  access_log /var/log/nginx/access.log;
  rewrite_log on;

  location / {
    proxy_pass  http://example.com;
    proxy_redirect     off;
    proxy_set_header   Host             $host;
    proxy_set_header   X-Real-IP        $remote_addr;
    proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;

    client_max_body_size       10m;
    client_body_buffer_size    128k;

    proxy_connect_timeout      90;
    proxy_send_timeout         90;
    proxy_read_timeout         90;

    proxy_buffer_size          4k;
    proxy_buffers              4 32k;
    proxy_busy_buffers_size    64k;
    proxy_temp_file_write_size 64k;
   }

  location ~ ^/(images|javascripts|stylesheets|assets|system)/  {
    root /home/myuser/apps/example/current/public;
    expires max;
    break;
   }

}

将此附加到
etc/nginx/sites available/default

location ~ ^/(robots.txt|sitemap.xml.gz) {
  root /home/<user>/apps/<appname>/current/public;
}
location~ ^/(robots.txt | sitemap.xml.gz){
root/home//apps//current/public;
}

您可以再编写一条位置规则,如

server {
  listen 80 default;
  server_name example.com www.example.com;
  root /home/myuser/apps/example/current/public;
 access_log /var/log/nginx/access.log;
 rewrite_log on;

location / {
proxy_pass  http://example.com;
proxy_redirect     off;
proxy_set_header   Host             $host;
proxy_set_header   X-Real-IP        $remote_addr;
proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;

client_max_body_size       10m;
client_body_buffer_size    128k;

proxy_connect_timeout      90;
proxy_send_timeout         90;
proxy_read_timeout         90;

proxy_buffer_size          4k;
proxy_buffers              4 32k;
proxy_busy_buffers_size    64k;
proxy_temp_file_write_size 64k;
}

location ~ ^/(images|javascripts|stylesheets|assets|system)/  {
root /home/myuser/apps/example/current/public;
expires max;
break;
}
location ~ ^/(robots.txt|sitemap.xml.gz)/  {
root /home/myuser/apps/example/current/public;

}

}

将此附加到etc/nginx/sites available/{您的应用程序配置文件}:

location ~ .*(robots.txt|sitemap.xml.gz) {
  # if you already set root above, then the following line is not needed.
  root /path_to_app/public;
}

那对我不起作用,我必须做
location~^/+\.(gz|txt)${}
。那对我不起作用,我必须做
location~^/+\.(gz|txt)${}