2017-02-20 4 views
0

すでに動作している書き換えルールを.htaccessからnginxに変換しようとしています。 私のアプリケーションにはバックエンド(/ admin/*で始まるすべてのコール)とフロントエンドの2つのモードがあり、残りの呼び出しがあります。バックエンドリクエストはadmin.phpに転送されますが、フロントエンドのものはindex.phpにルーティングされますmod_rewriteのルールをhtaccessからnginxに転送する

これはapacheではうまくいきますが、nginxでうまく動作します。/admin /要求はadmin.phpファイルを呼び出しますが、実行される代わりにphpファイルがダウンロードされます。私は既にhttp://winginx.comを使用してhtaccessのルートをnginxに変換しましたが、まだ/ adminのために動作するようにはできません。

これを行うには、nginxプロが適切な設定で私を助けますか? カール-sやっ上のnginxと

server { 
    listen  80; 
    server_name mydomain.local; 
    root /var/www/project; 
    index index.php index.html index.htm; 
    access_log /var/log/nginx/default-access.log main; 
    error_log /var/log/nginx/default-error.log; 

    error_page 500 502 503 504 /50x.html; 

    location = /50x.html { 
     root /var/www/default; 
    } 

    location/{ 
     rewrite sitemap.xml$ /index.php?_extension=Frontend&_controller=Sitemap&action=googleSitemap redirect; 
     try_files $uri $uri/ @rewrite; 
    } 
    location @rewrite { 
     rewrite ^(.*)$ /index.php; 
    } 
    location /admin { 
     rewrite ^/admin/(.*)$ /admin.php?$query_string break; 
    } 

    location ~ \.php { 
     include     fastcgi_params; 
     fastcgi_keep_conn on; 
     fastcgi_index   index.php; 
     fastcgi_split_path_info ^(.+\.php)(/.+)$; 
     fastcgi_param PATH_INFO $fastcgi_path_info; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
     fastcgi_intercept_errors on; 
     fastcgi_pass unix:/var/run/php-fpm.sock; 
    } 
} 

、...

<IfModule mod_rewrite.c> 
#RewriteBase/

# Google sitemap.xml configuration 
RewriteRule sitemap.xml$ /index.php?_extension=Frontend&_controller=Sitemap&action=googleSitemap [L,R=301] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.+)\.(\d+)\.(php|js|css|png|jpg|gif|gzip)$ $1.$3 [L] 

# admin routes 
RewriteRule ^/admin/(.*)$ admin.php?%{QUERY_STRING} [L] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-l 

# frontend routes 
RewriteRule .* index.php [L] 

</IfModule> 

、これは私がこれまで試したnginxの設定です:

は、これは私の作業の.htaccessの設定です-D - 'http://mydomain.local/frontend/call' | head -n 20
は、content-typeをtext/htmlとして返しますが、 curl -s -D - 'http://cms.dev/admin/whatever'にコールしています。 head -n 20はダウンロードをトリガーするapplication/octet-streamコンテンツタイプを返します。

答えて

0

最後に私はの場所/ adminの部分をこれに置き換えました。すべての/ adminコールは適切に処理されているようです。今、私はこれが最良か最適な方法かどうかは分かりませんが、それがうまくいくかどうかはわかりません。

location /admin { 
    try_files $uri $uri/ /admin.php?$query_string; 
} 
関連する問題