iT邦幫忙

0

nginx 500錯誤

想將原本是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

Further relax access to the default document root:

<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;
}
}

看更多先前的討論...收起先前的討論...
wordsmith iT邦高手 1 級 ‧ 2018-03-13 10:26:31 檢舉
先把 error log 的註解打開,再看看它報什麼錯吧,這樣比較快
hsiang11 iT邦好手 1 級 ‧ 2018-03-13 10:49:12 檢舉
我記得有看過error log也沒發現有啥錯誤
apache的設定檔
<Directory "/var/www">
nginx設定檔
root /var/www/html/testapi;

確定這兩個目錄的東西是一樣的 ?
hsiang11 iT邦好手 1 級 ‧ 2018-03-13 11:24:52 檢舉
發大 nginx是另開的測試機 所以目錄的路徑沒錯
apache的檔案是放在/var/www/html
我認為關鍵的地方apache多設了跨域存取
Header set Access-Control-Allow-Origin "*"
apache在處理php問題非常方便,只要檔案放在同目錄下就好
但是nginx看來會有很多location,別名等等的問題要處理
weiclin iT邦高手 4 級 ‧ 2018-03-13 11:44:52 檢舉
拿你的設定去跑, 除了少了分號以外沒有錯誤
wordsmith iT邦高手 1 級 ‧ 2018-03-13 12:04:52 檢舉
nginx 都報500了,log的一定會有內容的吧
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友回答

立即登入回答