【问题标题】:Mod_rewrite on Nginx?Mod_rewrite 在 Nginx 上?
【发布时间】:2014-12-31 11:02:56
【问题描述】:

我正在尝试在我的 Nginx 服务器上安装 GitList (http://gitlist.org/)。但是,安装的一部分是我使用以下代码更改了 Apache 配置文件:

<Directory "/var/www/html">
    # Other lines omitted
    AllowOverride All
    # Other lines omitted
</Directory>

此外,在 GitList 文件夹内的 .htaccess 文件中也需要此文件:

<IfModule mod_rewrite.c>
    Options -MultiViews +SymLinksIfOwnerMatch

    RewriteEngine On
    #RewriteBase /path/to/gitlist/

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php/$1 [L,NC]
</IfModule>
<Files config.ini>
    order allow,deny
    deny from all
</Files>

如何在 Nginx 中执行此步骤?

【问题讨论】:

    标签: apache .htaccess mod-rewrite nginx


    【解决方案1】:

    原来这是需要添加的:

    server {
        server_name MYSERVER;
        access_log /var/log/nginx/MYSERVER.access.log combined;
        error_log /var/log/nginx/MYSERVER.error.log error;
    
        root /var/www/DIR;
        index index.php;
    
    #   auth_basic "Restricted";
    #   auth_basic_user_file .htpasswd;
    
        location = /robots.txt {
            allow all;
            log_not_found off;
            access_log off;
        }
    
        location ~* ^/index.php.*$ {
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    
            # if you're using php5-fpm via tcp
            fastcgi_pass 127.0.0.1:9000;
    
            # if you're using php5-fpm via socket
            #fastcgi_pass unix:/var/run/php5-fpm.sock;
    
            include /etc/nginx/fastcgi_params;
        }
    
        location / {
            try_files $uri @gitlist;
        }
    
        location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
            add_header Vary "Accept-Encoding";
            expires max;
            try_files $uri @gitlist;
            tcp_nodelay off;
            tcp_nopush on;
        }
    
    #   location ~* \.(git|svn|patch|htaccess|log|route|plist|inc|json|pl|po|sh|ini|sample|kdev4)$ {
    #       deny all;
    #   }
    
        location @gitlist {
            rewrite ^/.*$ /index.php;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2014-03-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-13
      • 2013-02-02
      • 2012-07-28
      • 2015-09-20
      • 2012-07-19
      相关资源
      最近更新 更多