【发布时间】:2016-07-10 10:32:16
【问题描述】:
我已经在 apache 服务器中实现了 Rest Api(Post),但是当我将它移到 nginx 时它不起作用。这是我在名为 .htaccess 的根目录中使用的配置文件。
<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>
它所做的只是如果一个请求到达我的服务器的 ipaddess,例如 example.com/promocode_api/validate,它会向 api.php 发送请求来处理它。 但是无法在 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;
}
}
【问题讨论】: