如何使PHP脚本可执行而不是使用nginx下载

Recently I set up a virtual machine through vagrant and I'm using nginx as a web server. The OS I'm using for the VM is Ubuntu Linux 12.04. The problem is that any script I write in PHP gets downloaded, instead of being executed on the browser. Seeing as the PHP interpreter is normally installed I figured I'd post here the config file of nginx, as this is where the problem is likely to be found. Being a novice in the world of web development, I can't figure out what is out of the ordinary, can you guys take a look and tell me if you see something wrong? Thanks.

server {
  listen 80;

  server_name localhost;
  root /vagrant/www/web;

  error_log /var/log/nginx/error.log;
  access_log /var/log/nginx/access.log;

  #strip app.php/ prefix if it is present
  rewrite ^/app\.php/?(.*)$ /$1 permanent;

  location / {
    index app.php;
    try_files $uri @rewriteapp;
  }

  location @rewriteapp {
    rewrite ^(.*)$ /app.php/$1 last;
  }

  # pass the PHP scripts to FastCGI server listening socket
  location ~ ^/(app|app_dev)\.php(/|$) {
    fastcgi_pass unix://var/run/php5-fpm.sock;
    fastcgi_keep_conn on;
    fastcgi_split_path_info ^(.+\.php)(/.*)$;
    include fastcgi_params;
    fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
    fastcgi_param  HTTPS              off;
  }

  # enable global phpMyAdmin
  location /phpmyadmin {
    root /usr/share/;
    index index.php index.html index.htm;
    location ~ ^/phpmyadmin/(.+\.php)$ {
      try_files $uri =404;
      root /usr/share/;
      fastcgi_pass unix://var/run/php5-fpm.sock;
      fastcgi_index index.php;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      include /etc/nginx/fastcgi_params;
    }
    location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
      root /usr/share/;
    }
  }
  location /phpMyAdmin {
    rewrite ^/* /phpmyadmin last;
  }
}
查看全部
duanque3125
duanque3125
2015/08/30 21:11
  • nginx
  • vagrant
  • php
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

2个回复