1

eコマースサイトを開発しています。Ruby on Rails.Nginx を Web サーバーとして使用し、Unicorn をアプリケーション サーバーとして使用しています。私のアプリケーションでは、支払いページのみにsslを実装したいと考えています。これは、特定のURLのみを意味します。途中で設定しようとしました。gem 'rack-ssl-enforcer'を使用しています。環境ファイルで以下のように指定したgem構成

config.middleware.use Rack::SslEnforcer,
 :redirect_to => 'https://demo.domain.com',    # For when behind a proxy, like nginx
 :only => [/^\/payment\//],                      # Force SSL on everything behind /admin   and /authors
 :strict => true 

そして、以下のようにnginxを設定します。一般的なhttp://用とssl(https://)用の 2 つのサーバー ブロックを用意しました。

upstream unicorn_domain {
 # This is the socket we configured in unicorn.rb
server unix:/home/ubuntu/root_path/tmp/sockets/unicorn.sock fail_timeout=30;
} 

server {
listen 80;
client_max_body_size 4G;
server_name demo.domain.com;

keepalive_timeout 5;

# Location of our static files
root /home/ubuntu/1DRecruit/root_path/public;
access_log /home/ubuntu/root_path/log/nginx/nginx.access.log;
location / {


  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_set_header Host $http_host;
  proxy_redirect off;

  # 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_domain;
    break;
  }

  if ($request_uri ~* "\.(ico|css|js|gif|jpe?g|png)\?[0-9]+$") {
    expires max;
    break;
  }

}

}

 server {
    listen 443 ssl;
    client_max_body_size 4G;
    ssl                   on;
    ssl_certificate       /etc/nginx/ssl/example.com_chain.pem;
    ssl_certificate_key   /etc/nginx/ssl/example.com.key;
    ssl_protocols         SSLv3 TLSv1;
    ssl_ciphers           ALL:-ADH:+HIGH:+MEDIUM:-LOW:-SSLv2:-EXP;
    ssl_session_cache     shared:SSL:10m;


    keepalive_timeout 5;
# Location of our static files
    root /home/ubuntu/root_path/public;
   location / {
         proxy_set_header   X-Forwarded-Proto https;

}

}

このように構成した後、nginx は再起動中にエラーを表示せず、サイトを取得すると正しく読み込まれます。しかし、支払いページに移動すると、URL はhttps://に変わりますが、表示され、nginx エラー404 Not found が表示されます。nginx エラー ログを取得すると、表示されるエラーは次のとおりです。

[error] 2532#0: *1 open() "/home/ubuntu/root_path/public/payment/make_payment" failed (2: No such file or directory), client: 110.235.112.69, server: , request: "GET /payment/make_payment?id=9 HTTP/1.1", host: "demo.domain.com", referrer: "http://demo.domain.com/posters/home"

私は証明書にstartsslを使用しています。問題がわかりません。そして、問題を解決することは非常に重要です.誰かがこの問題で私を助けてくれますか.

よろしくお願いします

4

1 に答える 1