网上相关教程很多,这里就不细述了,主要是在安装完成后会出现页面空白,无法正常解析php。
1、安装php环境:
sudo apt-get install nginx php5-fpm php5-cgi php5-cli php5-curl php5-gd php5-mcrypt php5-mysql php5-memcache php5-gd php5-sqlite php5-cgi php5-xmlrpc mysql-server mysql-client
如果不需要mysql环境,去掉最后两个 mysql-server mysql-client
2、修改站点配置文件:
sudo nano /etc/nginx/sites-available/default
修改为以下内容:
server { listen 80; server_name raspiweb.dyndns.org; root /var/www/; access_log /var/log/nginx/localhost.access.log; #error_page 404 /404.html; if (!-e $request_filename) { rewrite ^(.*)$ /index.php$1 last; } location / { index index.html index.htm index.php default.html default.htm default.php; } location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ { access_log off; expires 1d; } location ~ .*\.php(\/.*)*$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
需要说明的是,站点目录为/var/www/,重点关注这一句:
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
如果少了就加上。