0

私は Web サーバーで Nginx を使用していますが、ここで書き換えがどのように機能するかを完全には理解していません。Apacheで動作するようになりました。

私は MVC ベースの PHP プロジェクトを使用しており、Apache で行ったようにクリーンな URL を使用したいと考えています。

www.domain.com/index.php?url=home/index正常に動作します。 www.domain.com/home/index動作しません。ご覧のとおり、最後の URL のようなきれいな URL が必要です。

私はいくつかの書き換えを試みましたが、try_files を使うべきか、書き換えるべきかわかりません。しかし、後で書き直したと思います。

私が言ったように、私はまだ書き直しを学んでいます。私のサーバーブロックは次のようになります。

server {

listen 80 default_server;
listen [::]:80 default_server ipv6only=on;

root /usr/share/nginx/html/pub/;
index index.php index.html index.htm;

server_name localhost;

location / {
    try_files $uri $uri/ @rewrite;
}

location @rewrite {
    rewrite ^/index.php?$arg_url /$arg_url permanent;
}

location ~ \.php$ {
    try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
}

}

私の書き換えブロックは理にかなっていると思いましたが、そうではないと思います。いくつかの書き換えを試みましたが、500 または 404 エラーが発生しました。そして、私が言ったように、私はまだ書き直していません。始めるには助けが必要です。

前もって感謝します。

4

2 に答える 2

0

これを試してください:

server {

listen 80 default_server;
listen [::]:80 default_server ipv6only=on;

root /usr/share/nginx/html/pub/;
index index.php index.html index.htm;

server_name localhost;

location / {
    try_files $uri $uri/ @rewrite;
}

location @rewrite {
    rewrite ^/(.*)$ /index.php?url=$1 last;
}

location ~ \.php$ {
    try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
}

}
于 2015-07-08T19:02:52.243 に答える