想將原本是apache的api server更換為nginx
這個api server原本是用在手機的app的
換nginx測試卻出現500: Internal Server Error
然後app就被關閉了
apache的設定檔
<Directory "/var/www">
AllowOverride None
# Allow open access:
Require all granted
<Directory "/var/www/html">
Header set Access-Control-Allow-Origin "*"
Options -Indexes
AllowOverride All
Require all granted
根目錄的htaccess
Options -Indexes
RewriteEngine On
RewriteBase /
# Force to exclude the trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.*)/$
RewriteRule ^(.+)/$ $1 [R=307,L]
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [QSA,L]
我的nginx設定檔寫法 要怎麽看出設定檔是不是哪裡寫錯了?
server {
listen 80;
server_name xxx.abc.com.tw
root /var/www/html/testapi;
index index.html index.php index.htm;
#access_log /var/log/nginx/webview/webview_access_log;
#error_log /var/log/nginx/webview/webview_error_log error;
include dropfavicon.conf;
location / {
alias /var/www/html/testapi/;
add_header 'Access-Control-Allow-Origin' '';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST,PUT, OPTIONS';
if (!-e $request_filename){
rewrite ^/(.+)/$ /$1 redirect;
}
if (!-e $request_filename){
rewrite ^(.)$ /index.php?$1 break;
}
index index.php index.html index.htm
autoindex off;
allow all;
try_files $uri $uri/ /index.php?$query_string;
}
location ~ .php$ {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, OPTIONS';
root /var/www/html;
fastcgi_pass 127.0.0.1:9001;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
include /etc/nginx/fastcgi_params;
}
}