[nginx]nginx的一個奇葩問題 500 Internal Server Error
解決方案
nginx 一直報500 Internal Server Error 錯誤,配置是通過phpstudy2018站點域名管理生成的。
默認是 root "D:\php\phpstudy\PHPTutorial\WWW\foxphp";
修改成這樣就好了
root "D:\\php\\phpstudy\\PHPTutorial\\WWW\\foxphp";
查找了很多資料,因為很奇葩,木有多少可供參考的,之前配置單斜杠一直木有問題,也找不到為毛產生的。有人說是地址問題,或許是單斜杠被當成轉義符號了吧,那就再加一個,然后就沒有然后了,php網站可以通過域名正常訪問了。
好吧,nginx我確實沒有系統的從頭到尾學習,一般能有就好。個人愚見,遇見了奇葩問題就記錄了下來進行分享,或許能夠給別人帶來幫助。
server { listen 80; server_name k.cn ; root "D:\\php\\phpstudy\PHPTutorial\\WWW\\kppw"; location / { index index.html index.htm index.php; #autoindex on; } location ~ \.php(.*)$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_split_path_info ^((?U).+\.php)(/?.+)$; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; include fastcgi_params; } } server { listen 80; server_name t.cn ; root "D:\\php\\phpstudy\PHPTutorial\\WWW\\thinkphp\\public"; location / { index index.html index.htm index.php; #autoindex on; } location ~ \.php(.*)$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_split_path_info ^((?U).+\.php)(/?.+)$; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; include fastcgi_params; } } server { listen 80; server_name o.cn ; root "D:\\php\\phpstudy\PHPTutorial\\WWW\\opensns"; location / { index index.html index.htm index.php; #autoindex on; } location ~ \.php(.*)$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_split_path_info ^((?U).+\.php)(/?.+)$; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; include fastcgi_params; } } server { listen 80; server_name f.cn ; root "D:\\php\\phpstudy\\PHPTutorial\\WWW\\foxphp"; location / { index index.html index.htm index.php; #autoindex on; } location ~ \.php(.*)$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_split_path_info ^((?U).+\.php)(/?.+)$; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; include fastcgi_params; } } server { listen 80; server_name abc.cn; root "D:\\php\\phpstudy\\PHPTutorial\\WWW\\test"; location / { index index.html index.htm index.php; autoindex on; } location ~ \.php(.*)$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_split_path_info ^((?U).+\.php)(/?.+)$; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; include fastcgi_params; } }
linux-lnmp-nginx 配置
server { listen 80; #listen [::]:80; server_name l.cn *.l.cn; index index.html index.htm index.php default.html default.htm default.php; root /home/landv/php/fastadmin-weike/public; include rewrite/thinkphp.conf; #error_page 404 /404.html; # Deny access to PHP files in specific directory #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; } include enable-php-pathinfo.conf; location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; } location ~ .*\.(js|css)?$ { expires 12h; } location ~ /.well-known { allow all; } location ~ /\. { deny all; } access_log /home/wwwlogs/l.cn.log; }
出現當前權限不足,無法寫入配置文件application/database.php解決方法
/user/local/nginx/conf/fastcgi.conf簡單粗暴修改這個文件
把fastcgi_param PHP_ADMIN_VALUE值修改即可
fastcgi_param PHP_ADMIN_VALUE "open_basedir=/home/landv/php/fastadmin-weike/:/tmp/:/proc/";
lnmp集成環境默認在最后一行。
因為lnmp默認會在虛擬主機目錄創建一個.user.ini文件里面保存的是虛擬主機根目錄配置信息
#fastcgi_param PHP_ADMIN_VALUE "open_basedir=$document_root:/tmp/:/proc/" ;
這個可以注釋掉他。好吧坑那么多。
還會出現其他文件權限問題,反正測試使用直接給到最大權限,正式使用的時候,只能給部分目錄開放權限。
chmod -R 777 *
lnmp .user.ini文件無法刪除解決方法
使用命令lnmp vhost del刪除虛擬主機后,需要使用ftp或者rm命令刪除網站目錄,但是卻發現網站目錄下有個文件.user.ini文件沒有自動刪除,出現提示rm: cannot remove `http://xxx.com/.user.ini’: Operation not permitted,連手動ftp也無法刪除。
問題分析:根據上面的提示判斷文件權限已經被鎖定,需要先解除鎖定。
問題解決:輸入以下命令
chattr -i /home/wwwroot/你的網站目錄/.user.ini
然后再用rm -rf命令或者FTP去刪除就可以了。
隱藏thinkphp的index.php url,可以不用改成和官方的一樣
修改lnmp的pathinfo.conf文件
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
修改成
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
thinkphp 隱藏index.php
server { listen 80; server_name fast.cn ; root "D:\\php\\phpstudy\\PHPTutorial\\WWW\\thinkphp\\fastadmin-weike\\public"; location / { index index.html index.htm index.php; if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=/$1 last; break; } #autoindex on; } location ~ \.php(.*)$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_split_path_info ^((?U).+\.php)(/?.+)$; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; include fastcgi_params; } }
真正起作用的是這一段配置:
if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=/$1 last; break; }