将所有/*.html或/*/*.html重定向到主页

时间:2016-01-31 20:43:10

标签: ruby-on-rails regex nginx server unicorn

我的网站有链接/page1.html或/category/category-page.html。现在,此站点已移至Rails应用程序,并且它具有宁静的路由。我使用unicorn作为应用服务器。我想将所有类型的上述URL重定向到我的新应用程序的主页。我目前正在进行以下配置。请帮我写配置。

upstream unicorn {
 server unix:/tmp/unicorn.sock fail_timeout=0;
}

server {
  listen 80;
  server_name example.com;
  root /srv/www/example/current/public;


  access_log /var/log/nginx/example.access.log;
  keepalive_timeout 5;


  location / {
    try_files $uri/index.html $uri/index.htm @unicorn;
  }

  location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }

  location @unicorn {
    proxy_set_header      X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_redirect off;
    proxy_set_header        Host $host;
    proxy_set_header        X-Real-IP $remote_addr;
    proxy_set_header        X-Forwarded-Proto $scheme;


    # If you don't find the filename in the static files
    # Then request it from the unicorn server
    if (!-f $request_filename) {
      proxy_pass http://unicorn;
      break;
    }
  }

 location /nginx_status {
    stub_status on;
    access_log off;
    allow 127.0.0.1;
    deny all;
  }

  error_page 500 502 503 504 /500.html;
  location = /500.html {
    root /var/www/example/current/public;
  }

}

0 个答案:

没有答案