# vim /usr/local/nginx/conf/nginx.conf http { server { listen 80; server_name localhost; root html; index index.html index.php; location ~ \.php$ { try_files $uri = 404; include fastcgi.conf; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } } }
然后编写一个简单的php文件,用来显示当前PHP环境信息:
# vim /usr/local/nginx-1.6.2/html/phpinfo.php <?php phpinfo(); ?> # chown -R www:www /usr/local/nginx-1.6.2
启动Nginx,并打开浏览器访问地址应该可以看到:
至此,Nginx与PHP已经可以正常协同工作。