未遵守Nginx的位置指令

未遵守Nginx的位置指令,nginx,Nginx,我有一个RubyonRails应用程序,它与下面粘贴的nginx配置配合得很好。问题是,我正在尝试添加一个新的urlhttp://www.example.com/gpp将指向服务器上的完整目录路径/app。以下是我的配置: upstream fi { server unix:/media/apps/example/shared/tmp/pids/thin.0.sock; server unix:/media/apps/example/shared/tmp/pids

我有一个RubyonRails应用程序,它与下面粘贴的nginx配置配合得很好。问题是,我正在尝试添加一个新的url
http://www.example.com/gpp
将指向服务器上的完整目录路径/app。以下是我的配置:

upstream fi {
        server unix:/media/apps/example/shared/tmp/pids/thin.0.sock;
        server unix:/media/apps/example/shared/tmp/pids/thin.1.sock;
        server unix:/media/apps/example/shared/tmp/pids/thin.2.sock;
        server unix:/media/apps/example/shared/tmp/pids/thin.3.sock;
}

server {

  listen 80;
  gzip on;
  gzip_min_length 1000;
  gzip_types application/json text/css application/x-javascript;

  server_name example.com www.example.com;

  sendfile on;

  keepalive_timeout 65;
  client_max_body_size 2m;

  proxy_set_header  X-Real-IP  $remote_addr;
  proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_set_header  X-Forwarded-Proto $scheme;
  proxy_set_header  Host $http_host;

  #root /media/apps/example/current/public;

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

  location ~ \.php$ {
    root           /usr/share/nginx/html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
        include        fastcgi_params;
  }  


  location / {
    root /media/apps/example/current/public;
    proxy_set_header  X-Real-IP  $remote_addr;
    proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header  X-Forwarded-Proto $scheme;
    proxy_set_header  Host $http_host;
    proxy_connect_timeout 3600;
    send_timeout 3600;
    proxy_read_timeout 3600;
    if (!-f $request_filename) {
     proxy_pass http://fi;
     break;
    }
  }

  location /gpp {
      alias /media/apps/podcast;
      index index.php index.html index.htm;
  }

}

每当我访问
http://www.example.com/gpp
它只是转到
位置中列出的Rails应用程序,而不是我在
/media/apps/podcast中运行的PHP应用程序。我还尝试将
别名
指令更改为
,但这也不起作用。

我没有看到您的
/media/apps/podcast
别名的
位置
指令。我觉得这个

location /gpp {
  alias /media/apps/podcast;
  index index.php index.html index.htm;
}
应该是

location /gpp {
  root /media/apps/podcast;
  index index.php index.html index.htm;
}
尝试一下:

location /podcast {
    root        /media/apps/;
    index       index.php index.html index.htm;

    location ~ ^/podcast/(.+\.php)$ {
        try_files      $uri =404;
        root           /media/apps/;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
    location ~* ^/podcast/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
        root    /media/apps/;
    }
}

location /gpp {
    rewrite ^/* /podcast last;
}

如果将/gpp更改为/gpp/并转到
http://www.example.com/gpp/
?似乎index指令只适用于以/在conf中添加正斜杠结尾的路径,但仍然会给出相同的结果不幸的是,您确定提供的配置是您正在测试的配置吗?也就是说,确保编辑配置后重新加载配置,并且重新加载成功-确保错误日志中没有错误。如果您正在使用浏览器进行测试(或者更好地使用telnet/nc/curl/whatever进行测试),请确保清除浏览器缓存。