Nginx 解析PHP
配置如下:
[root@localhost ~]$ cat /usr/local/nginx/conf/vhost/test.com.conf server { listen 80; server_name www.test.com; index index.html index.html index.php; root /data/www; location ~ \.php$ { include fastcgi_params; fastcgi_pass unix:/tmp/php-fcgi.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name; } }
# 关于 fastcgi_pass 配置,参考:https://segmentfault.com/q/1010000004854045
[root@localhost ~]$ /usr/local/nginx/sbin/nginx -t
[root@localhost ~]$ /usr/local/nginx/sbin/nginx -s reload
创建 php 文件:
[root@localhost ~]$ cat /data/www/1.php <?php phpinfo(); ?>
测试是否解析:
[root@localhost ~]$ curl -x 127.0.0.1:80 http://www.test.com/1.php # 没有解析到PHP的输出情况 <?php phpinfo(); ?>
[root@localhost ~]$ curl -x 127.0.0.1:80 http://www.test.com/1.php # 解析到PHP的输出情况 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"><head> <style type="text/css"> body {background-color: #fff; color: #222; font-family: sans-serif;} ......