如何将 Apache 的 `AllowOverride all` 转换为 nginx [英] How to convert Apache's `AllowOverride all` to nginx
问题描述
我有一个 Apache2 &Rails 应用的乘客站点,使用以下配置:
I have an Apache2 & Passenger site for Rails app, that uses following configuration:
<VirtualHost *:80>
ServerName localhost
DocumentRoot /var/www/site/public
<Directory /var/www/site/public>
AllowOverride all
Options -MultiViews
</Directory>
</VirtualHost>
是否有 nginx & 的等价物?客运站?目前 nginx 以 {ID}/action
和 404
的形式响应所有请求.这是nginx conf的相关部分:
Is there an equivalent for nginx & Passenger site? Currently nginx responds to all requests in form {ID}/action
with 404
. Here's the relevant part of nginx conf:
location / {
passenger_app_root /var/www/site;
passenger_document_root /var/www/site/public;
passenger_enabled on;
try_files $uri $uri/ =404;
}
应用中没有 .htaccess
文件.
推荐答案
乘客作者在这里.Nginx 中没有AllowOverride all"的等价物,您也不需要它.您只需要一个虚拟主机块,其中root"指向您应用的public"目录,并且passenger_enabled on":
Passenger author here. There is no equivalent for 'AllowOverride all' in Nginx, and you don't need it either. All you need is a virtual host block with the 'root' pointing to your app's 'public' directory, and 'passenger_enabled on':
server {
listen 80;
server_name www.example.com;
root /var/www/site/public;
passenger_enabled on;
}
...如乘客官方文档的部署说明.
passenger_app_root
和 passenger_document_root
是从 root
自动推断出来的.也不需要 try_files
,因为乘客 自动通过 Nginx 为您提供静态文件.
passenger_app_root
and passenger_document_root
are automatically inferred for you from root
. There is no need for try_files
either because Passenger automatically serves static files for you through Nginx.
您应该阅读官方文档.
这篇关于如何将 Apache 的 `AllowOverride all` 转换为 nginx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!