0

私は何年にもわたってグーグルで情報を探し、何人かの人々に尋ねました(誰かが私に行くように勧める前に)。

nginx.conf で正しく動作していない部分は以下のとおりです。何が機能しているか: BlogHome、Home、About に書き直します。

機能していないもの - C_ReadBlogURL および C_ReadAllPosts に書き換えます。これらは両方とも、パスが正しいにもかかわらず、何らかの理由で 404 になります。理由がわかりません - そして、私はこれについて一日中頭を悩ませてきました。それらがphpファイルであることと関係があるのではないかと思いますが、わかりません。

どんな助けでも大歓迎です:)

server {
listen   80;


server_name blog.example.com;

root /usr/share/nginx/www/example;
index /views/Read/BlogHome.php;


location / {
    rewrite ^/?$ /views/Read/BlogHome.php last; break;
    rewrite ^/(.+)/?$ /controllers/read/C_ReadBlogURL.php?url=$1 last; break;
}
location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
}
}

server {
listen 80;
server_name example.com;

root /usr/share/nginx/www/example;
index /controllers/read/C_ReadLatestPost.php;

location ~ ^(/posts\.php) {
    rewrite ^(/posts\.php)  /controllers/read/C_ReadAllPosts.php?type=$arg_type last; break;
}

location ~ ^/?$ {
    rewrite ^/?$ /controllers/read/C_ReadLatestPost.php last; break;


}

location ~ ^(/about)/?$ {
    rewrite ^(/about)/?$ /views/Read/About.php last; break;
}

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

}
4

2 に答える 2

0

最初のルールでは () は必要ありませんが、それは単なる詳細です。

あなたの問題は「break;」、「last;」だけだと思います。この場合の正しい選択です。

私はこれを試してみましたが、うまくいきます(test1.htmlとtest2.htmlのコンテンツは異なり、各ルールにいつ入るかがわかります):

rewrite ^/posts.php /test1.html?type=$arg_type last;
rewrite ^/(.+)/?$ /test2.html?url=$1 last;

したがって、これはうまくいくはずです:

rewrite ^/posts.php /controllers/read/C_ReadAllPosts.php?type=$arg_type last;
rewrite ^/(.+)/?$ /controllers/read/C_ReadBlogURL.php?url=$1 last;

またはあなたの最後の更新によると:

rewrite ^/posts\.php /controllers/read/C_ReadAllPosts.php?type=$arg_type last;
rewrite ^/?$ /views/Read/BlogHome.php last;
rewrite ^/(.+)/?$ /controllers/read/C_ReadBlogURL.php?url=$uri last;
于 2013-04-11T22:53:43.627 に答える