私はApacheのサーバでRest Api(Post)を実装しましたが、それをnginxに移動すると機能しません。ここには、.htaccessというルートディレクトリで使用されている設定ファイルがあります。残りのAPI用にNginxを設定する
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^(.*)$ api.php?rquest=$1 [QSA,NC,L]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ api.php [QSA,NC,L]
RewriteCond %{REQUEST_FILENAME} -s
RewriteRule ^(.*)$ api.php [QSA,NC,L]
</IfModule>
要求は、それを処理するために、api.php要求を送信するexample.com/promocode_api/validateのように自分のサーバーのipaddessになる場合はそれがないすべてがあります。 しかし、それを動作させるには、nginxで設定が必要になることはありません。
ここには/ etc/nginx/sites-enabled/defalutのnginxコードがあります。
server {
listen 80;
root /purple_dev;
index index.php index.html index.htm;
server_name example.com;
# location/{
# try_files $uri $uri/ /index.html;
# }
location /promocode_api {
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /purple_dev;
}
# pass the PHP scripts to FastCGI server listening on the php-fpm socket
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}