nginx + php7環境下,新建phalcon專案,rewrite問題
阿新 • • 發佈:2019-02-17
本文預設已經安裝好phalcon的extension與開發工具
1. 新建專案store
進入到專案根目錄www/html,然後執行:
phalcon create-project store
注意,個人理解,因為此時建立的專案包含apache的rewrite邏輯。若按照官網上教程,直接測試,會報錯:
Mod-Rewrite is not enabled
Please enable rewrite module on your web server to continue
所以還需要配置nginx的rewrite。
2. 配置nginx的rewrite
開啟nginx的配置檔案
sudo vim /etc/nginx/sites-enabled/<你的網站配置檔案>
在server{}中新增一行
為store新增rewrite規則
location /store/ {
rewrite ^/store/(.*)$ /store/public/index.php?_url=/$1;
}
完畢,現在可以按照官網的教程繼續玩耍了。
3.try_file 的用例,經過測試,結果正確
server { listen 8443; server_name localhost; location / { index index.html index.php index.htm; try_files $uri $uri/ /index.php?_url=$uri&$args; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } location ~\.php$ { root /PATH/php/public; #fastcgi_pass 127.0.0.1:9000; fastcgi_pass unix:/run/php-fpm/www.sock; fastcgi_index index.php; #fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } location ~ /\.ht { deny all; } }