Nginx显示PHP代码而不是执行

时间:2015-10-29 08:45:07

标签: php nginx

我已经在node.js上运行的nginx上运行app了。现在我必须在同一个nginx上运行php app。我在这里写我的配置文件供你细读。当我加热" http://192.168.1.201:3002/"在我的chrome / firefox浏览器中,它只显示/渲染所有PHP代码而不是执行代码。我是php和nginx的新手。

nginx.config

upstream app_stat {
    server 127.0.0.1:3001;  
    keepalive 80;
}

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /home/manish/workspace/statistics;
    index index.html index.htm;

    # Make site accessible from http://localhost/
    server_name localhost;

    access_log /dev/null;
    #error_log  /var/log/stat-error.log;

        # static resources
        location ~ ^/(robots.txt|humans.txt|favicon.ico) {
            root /home/manish/workspace/statistics;
            access_log on;
            expires max;
        }

    location = /favicon.ico {
        root /home/manish/workspace;
        log_not_found off;
    }

    location ~ /js/(.*) {
            add_header X-debug-message "A static file was served by pushstate";

            proxy_redirect off;
            proxy_set_header   X-Real-IP         $remote_addr;
            proxy_set_header   X-Forwarded-For   $proxy_add_x_forwarded_for;
            proxy_set_header   X-Forwarded-Proto $scheme;
            proxy_set_header   Host              $http_host;
            proxy_set_header   X-NginX-Proxy     true;

            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_pass         http://app_stat;
        }

        location ~ /socket.io/(.*) {
           add_header X-debug-message "A static file was served by pushstate";

            proxy_redirect off;
            proxy_set_header   X-Real-IP         $remote_addr;
            proxy_set_header   X-Forwarded-For   $proxy_add_x_forwarded_for;
            proxy_set_header   X-Forwarded-Proto $scheme;
            proxy_set_header   Host              $http_host;
            proxy_set_header   X-NginX-Proxy     true;

            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_pass         http://app_stat;
        }

       location ~ ^/(.+?)(/.*)?$ {
            add_header X-debug-message "A static file was served by pushstate";

            proxy_redirect off;
            proxy_set_header   X-Real-IP         $remote_addr;
            proxy_set_header   X-Forwarded-For   $proxy_add_x_forwarded_for;
            proxy_set_header   X-Forwarded-Proto $scheme;
            proxy_set_header   Host              $http_host;
            proxy_set_header   X-NginX-Proxy     true;

            proxy_http_version 1.1;
            proxy_set_header   Upgrade $http_upgrade;
            proxy_set_header   Connection "upgrade";
            proxy_pass         http://app_stat;
        }

    location / {
            if ($http_user_agent ~ (Googlebot|google|bing|yandex|msnbot|AltaVista|DuckDuckBot) ) {
               return 403;
            }

                add_header X-debug-message $http_accept;
                proxy_redirect off;
                proxy_set_header   X-Real-IP         $remote_addr;
                proxy_set_header   X-Forwarded-For   $proxy_add_x_forwarded_for;
                proxy_set_header   X-Forwarded-Proto $scheme;
                proxy_set_header   Host              $http_host;
                proxy_set_header   X-NginX-Proxy     true;

                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";

                proxy_pass         http://app_stat;
    }

}

# another virtual host using mix of IP-, name-, and port-based configuration

server {
    listen 3002;
    listen [::]:3002 ipv6only=on;

    #root /var/www/wagholigav.com/html;
    root /var/www/html/wagholigav/;
    index index.php index.htm index.html;

    server_name 192.168.1.201:3002;

    access_log  /dev/null;

    location / {
        try_files $uri $uri/ =404;
        #proxy_pass http://192.168.1.201;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $http_host;
        proxy_set_header X-Forwarded-Proto $scheme;
            proxy_buffering off;
        }

        #location ~ [^/]\.php(/|$) {
    location ~/.php$ {
        #try_files $uri =404;
        try_files $uri $uri/ =404;

        #proxy_pass http://192.168.1.201;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        if (!-f $document_root$fastcgi_script_name) {
                return 404;
            }

        fastcgi_pass unix:/var/run/php5-fpm.sock;
        #fastcgi_pass 127.0.0.1:9000;

            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

        include fastcgi_params; 
        #include fastcgi.conf;
    }
}
根目录

index.php

<?php 
    header('Location:Website/index.php');
?>
网站目录

index.php

<?php 
        header("Location:home.php");
?>

home.php

<?php 
    include("../conn.php");
    $date=date("Y-m-d");
?>
<!DOCTYPE html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
    <head>
        <meta charset="utf-8">

        <title>Home</title>
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">

        <!-- Place favicon.ico and apple-touch-icon.png in the root directory -->

        <link rel="stylesheet" href="css/bootstrap.css">
        <link rel="stylesheet" href="css/animations.css">
        <link rel="stylesheet" href="css/main.css">
        <script src="js/vendor/modernizr-2.6.2.min.js"></script>

    <script type="text/javascript" src="js/jquery.min.js"></script>
    <script type="text/javascript" src="js/jquery.migrate.js"></script>
    <script type="text/javascript" src="js/jquery.bxslider.min.js"></script>
    <script type="text/javascript" src="js/bootstrap.min.js"></script>
    <script type="text/javascript" src="js/jquery.imagesloaded.min.js"></script>
    <script type="text/javascript" src="js/jquery.isotope.min.js"></script>
    <script type="text/javascript" src="js/retina-1.1.0.min.js"></script>
    <script type="text/javascript" src="js/plugins-scroll.js"></script>
    <!-- SLIDER REVOLUTION 4.x SCRIPTS  -->
    <script type="text/javascript" src="js/jquery.themepunch.tools.min.js"></script>
    <script type="text/javascript" src="js/jquery.themepunch.revolution.min.js"></script>
    <script type="text/javascript" src="js/script.js"></script>
    <script type="text/javascript" src="js/plugins-scroll.js"></script>

    </head>
    <body><div id="top"></div>
        <!--[if lt IE 7]>
            <p class="chromeframe">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> or <a href="http://www.google.com/chromeframe/?redirect=true">activate Google Chrome Frame</a> to improve your experience.</p>
        <![endif]-->



<section id="topline" class="color_section">
  <div class="container">
    <div class="row">
      <div class="col-sm-6">
        <p><i class="rt-icon-mail3"></i> contact@website.com | 
        <a class="socialico-facebook" href="https://www.facebook.com/1417595XXXXXX" title="Facebook">#</a>
          </p>
      </div>
      <div class="col-sm-6">
        <p class="text-right"><i class="rt-icon-location"></i> City</p>
      </div>
    </div>
  </div>        
</section> 

<section id="header" class="bg-color0">
    <div class="container"><div class="row">

      <a class="navbar-brand" href="#top"><img src="example/logo1.png" height="50px" width="50px" alt=""> वाघोली ग्रामस्थ मंडल</a>

      <div class="col-sm-12 mainmenu_wrap"><div class="main-menu-icon visible-xs"><span></span><span></span><span></span></div>
        <ul id="mainmenu" class="nav menu sf-menu responsive-menu superfish">
          <li class="">
            <a href="#features">features</a>
          </li>
          <li class="">
            <a href="#title_about">about</a>
          </li>
          <li class="">
            <a href="#portfolio">portfolio</a>
          </li>
          <li class="">
            <a href="#team">team</a>
          </li>

          <li class="">
            <a href="#contact">contact</a>
          </li>
         </ul>
      </div>

    </div></div>
</section>


<section id="mainslider">
  <div class="slider-wrapper">
      <div class="responisve-container">
        <div class="slider">
        <!--  <div class="fs_loader"></div>-->
          <div class="slide">
            <img src="example/home_1.JPG" alt="" width="1920" height="550" data-position="0,0" data-in="fade" data-delay="0" data-out="fade">
          </div>
          <div class="slide" data-in="slideLeft">
            <img src="example/home_2.JPG" alt="" width="1920" height="550" data-position="0,0" data-in="fade" data-delay="0" data-out="fade">
          </div>
          <div class="slide" data-in="slideLeft">
            <img src="example/home_3.jpg" alt="" width="1920" height="550" data-position="0,0" data-in="fade" data-delay="0" data-out="fade">
           </div>
          <div class="slide" data-in="slideLeft">
            <img src="example/home_4.jpg" alt="" width="1920" height="550" data-position="0,0" data-in="fade" data-delay="0" data-out="fade">
           </div>
            <div class="slide" data-in="slideLeft">
            <img src="example/home_5.JPG" alt="" width="1920" height="550" data-position="0,0" data-in="fade" data-delay="0" data-out="fade">
           </div>
            <div class="slide" data-in="slideLeft">
            <img src="example/home_6.jpg" alt="" width="1920" height="550" data-position="0,0" data-in="fade" data-delay="0" data-out="fade">
           </div>
            <div class="slide" data-in="slideLeft">
            <img src="example/home_7.jpg" alt="" width="1920" height="550" data-position="0,0" data-in="fade" data-delay="0" data-out="fade">
           </div>

        </div>
      </div>
    </div>
</section>


<div id="box_wrap">

<section id="features" class="color_section">
 <div class="container">
    <div class="row">
        <div class="col-sm-3 text-center">
              <p>Some code</p>
          </div>
          <div class="col-sm-6 text-center">
             <h2 class="block-header">History</h2>
          </div>
          <div class="col-sm-3 text-center">
              <p>Some code2</p>
          </div>
    </div>
    <div class="row">
        <div class="col-sm-3 text-center">
             &nbsp;
          </div>
          <div class="col-sm-6 text-center">
             <p style="margin-top:-25px;">Area Country</p>
             <hr>
          </div>
          <div class="col-sm-3 text-center">
              &nbsp;
          </div>
    </div>
    <div class="row">
      <div class="col-sm-12">

          <div class="block widget_accordion">
            <div class="panel-group" id="accordion">

            <div class="panel panel-default">
                <div class="panel-heading">
                  <h4 class="panel-title">
                    <div style="font-size:16px;" class="accordion-toggle collapsed" >
                        some text content 
                    </div>
                  </h4>
                </div>
             </div>

             <div class="panel panel-default">
                <div class="panel-heading">
                  <h4 class="panel-title">
                    <div style="font-size:16px;" class="accordion-toggle collapsed" >
                        some text content2
                    </div>
                  </h4>
                </div>
              </div>
              <div class="panel panel-default">
                <div class="panel-heading">
                  <h4 class="panel-title">
                    <div style="font-size:16px;" class="accordion-toggle collapsed" >
                        some text content3
                    </div>
                  </h4>
                </div>
              </div>
              <div class="panel panel-default">
                <div class="panel-heading">
                  <h4 class="panel-title">
                    <div style="font-size:16px;" class="accordion-toggle collapsed" >
                        some text content4
                    </div>
                  </h4>
                </div>
              </div>

          </div>
        </div>
        </div>
    </div>
    <div class="row">
      <div class="col-sm-5">
                &nbsp;  
        </div>
        <div class="col-sm-4">
                <a href="history.php" target="_blank" class="theme_btn">read more...</a>
        </div>
        <div class="col-sm-3">
            &nbsp;
        </div>
    </div>
  </div>
</section>

<section class="title_section" id="title_about">
  <div class="container">

<div class="row">  
  <div class="col-lg-6">
  <div style="font-size:24px;color:#000;">Event</div></br>
      <?php $estr="SELECT * FROM `event_tbl` WHERE `edate`>='$date' ORDER BY `eid` DESC limit 5";
            $estr1=mysql_query($estr) or die(mysql_error());
            while($efa=mysql_fetch_array($estr1))
            {
            ?>
      <h4> <a href="sevent.php?eid=<?php echo $efa['eid'];?>" target="new"><?php echo $efa['ename'];?></a></h4>
      <p><?php  $s=$efa['edesc'];$s1=substr($s,0,100);echo $s1;?></p>
    <?php   } ?>
    </div>

   <div class="col-lg-6">
   <div style="font-size:24px;color:#000;">Past Event</div></br>
      <?php $estr="SELECT * FROM `event_tbl` WHERE `edate`<'$date' ORDER BY `eid` DESC limit 5";
            $estr1=mysql_query($estr) or die(mysql_error());
            while($efa=mysql_fetch_array($estr1))
            {
            ?>
      <h4> <a href="sevent.php?eid=<?php echo $efa['eid'];?>" target="new"><?php echo $efa['ename'];?></a></h4>
      <p><?php  $s=$efa['edesc'];$s1=substr($s,0,100);echo $s1;?></p>
    <?php   } ?>
    </div>

  </div></br></br>
  <div class="row">
      <div class="col-lg-6">
                &nbsp;  
        </div>
        <div class="col-lg-6">
                <a href="events.php" class="theme_btn" target="new">read more...</a>
        </div>
        <div class="col-lg-6">
            &nbsp;
        </div>
    </div>
  </div>
</section>

<section id="portfolio" class="fullwidth_portfolio grey_section">
    <div class="container"><div class="row">
      <div class="col-sm-12 text-center">
          <h2 class="block-header">Gallary</h2>
          <p>Watch more<a class="socialico-facebook" href="https://www.facebook.com/141759572XXXXXX" title="Facebook"> इथे </a> Click here | </p>

      </div>
    </div>
  </div>
<div id="portfolio_wrapper">
      <ul class="items-row row cols-3 portfolio filtrable clearfix isotope" id="portfolioContainer">

<?php $gstr="SELECT * FROM `event` WHERE `edate`>='$date' ORDER BY `eid` DESC limit 8";
            $gstr1=mysql_query($gstr) or die(mysql_error());
            while($gfa=mysql_fetch_array($gstr1))
            {
            ?>

        <li class="item isotope-item">
          <div class="portfolio_item_image">
            <?php $gifa=mysql_fetch_array(mysql_query("SELECT * FROM `imgs` where eventid=".$gfa['eid']." ORDER BY `eventid` ASC"));?>
             <a href="./gshow.php?eid=<?php echo $gfa['eid'];?>" target="new"><img alt="" src="<?php echo $gifa['imgpath'];?>" ></a>
          </div>
          <div class="item_title">
            <h4>
              <a href="./gshow.php?eid=<?php echo $gfa['eid'];?>"  target="new"><?php echo $gfa['ename']; ?></a>
            </h4>
          </div>
        </li>
        <?php   } ?>
         <li class="item isotope-item">
              <div class="portfolio_item_image">
                 <img alt="" src="example/64.jpg" ></a>
              </div>
              <div class="item_title">
                <h4>
                 photo
                </h4>
              </div>
            </li>

            <li class="item isotope-item"> 
              <div class="portfolio_item_image">
                <img alt="" src="example/74.jpg" >           
              </div>
              <div class="item_title">
                <h4>
                  Photo
              </div>     
            </li>

      </ul>
</br></br>
    <div class="row">
      <div class="col-sm-5">
                &nbsp;  
        </div>
        <div class="col-sm-4">
                <a href="gallery.php" target="_blank" class="theme_btn">Read more...</a>
        </div>
        <div class="col-sm-3">
            &nbsp;
        </div>
    </div>
  </div>  
  </br>
  </br>
</section>

<section id="team" class="">
  <div class="container">

  <div class="row">
      <div class="col-sm-12 text-center">
          <h2 class="block-header">member</h2>
          <p>
            content  content content content
      </p>
      </div>
  </div>
    <div class="accordion-box ">
        <?php $kstr="SELECT * FROM `kamiti_tbl` GROUP BY `kstatus` ORDER BY `kstatus` DESC";
              $kstr1=mysql_query($kstr) or die(mysql_error());
              while($kfa=mysql_fetch_array($kstr1))
              {?>
        <div class="accord-elem ">
            <div class="accord-title">
                <a class="accord-link" href="#"></a>
                <h2>कमिटी मेंबर (<?php echo $kfa['kyear']?>) ते आजपर्यंत)  </h2>
            </div>
            <div class="accord-content">
            <?php $mstr="SELECT * FROM `kamiti` where `kstatus`=".$kfa['kstatus'];
                    $mstr=mysql_query($mstr) or die(mysql_error());
                    while($mfa=mysql_fetch_array($mstr))
                    {?>

                <div class="block col-md-3 col-sm-6" style="margin-top:25px;">
                    <center>
                        <div class="thumbnail">
                            <img src="<?php echo $mfa['kimg'];?>" alt="team" style="width:130px;height:150px;">
                            <div class="caption">
                                <h4><?php echo $mfa['kname'];?></h4>
                                <p><?php echo $mfa['kdp'];?></p>
                            </div>
                        </div>
                    </center>
                </div>

            <?php } ?>
            </div>
        </div>
    <?php } ?>
    </div>
</div>
</section>
<section id="contact" class="darkgrey_section parallax">
  <div class="container">
    <div class="row">
      <div class="col-sm-12 text-center">
        <h2 class="block-header">contact</h2>
      </div>
    </div>
    <div class="row">
      <div class="col-sm-6">
        <div class="contact-form">
          <form method="get" action="sendmail.php">
            <p class="contact-form-name">
              <label for="name">Name <span class="required">*</span></label>
              <input type="text"  size="30" value="" name="name" id="name" class="form-control" required />
            </p>
             <p class="contact-form-email">
              <label for="email">Phone Number <span class="required">*</span></label>
              <input type="text" aria-required="true" size="30" value="" name="mo" id="email" class="form-control" placeholder="Phone Number" required>
            </p>
            <p class="contact-form-email">
              <label for="email">Email <span class="required">*</span></label>
              <input type="email" aria-required="true" size="30" value="" name="em" id="email" class="form-control" placeholder="Email" required>
            </p>
            <p class="contact-form-message">
              <label for="message">Comment</label>
              <textarea aria-required="true" rows="5" cols="45" name="msg" id="message" class="form-control" placeholder="Message" required></textarea>
            </p>
            <p class="contact-form-submit text-center vertical-margin-81">
              <input type="submit" value="Send" name="send" class="theme_btn">
            </p>
          </form>
        </div>
      </div>

      <div class="block widget_text col-sm-3">
        <p>some text content<br> 
          some text content<br> 
          <span><strong> Mr X   - </strong> </span>9999999<br>
          <span><strong>Mr y   - </strong> </span>888888<br>
          <span><strong>Email:</strong> </span>
          <a href="mailto:info@company.com">contact@website.com</a><br> 

        </p>
        <p>
          <a class="socialico-facebook" href="https://www.facebook.com/141759572XXXXXX" title="Facebook">#</a>
          </p>
      </div>
    </div>
  </div>
</section>

</div><!-- EOF #box_wrap -->

<div id="gallery_container"></div>
        <script src="js/vendor/respond.min.js"></script>
        <script src="js/vendor/placeholdem.min.js"></script>
        <script src="js/vendor/jquery-1.10.2.min.js"></script>
        <script src="js/vendor/bootstrap.min.js"></script>
        <script src="js/vendor/hoverIntent.js"></script>
        <script src="js/vendor/superfish.js"></script>
        <script src="js/vendor/jquery.actual.min.js"></script>
        <script src="js/vendor/jquery.elastislide.js"></script>
        <script src="js/vendor/jquery.flexslider-min.js"></script>
        <script src="js/vendor/jquery.prettyPhoto.js"></script>
        <script src="js/vendor/jquery.easing.1.3.js"></script>
        <script src="js/vendor/jquery.ui.totop.js"></script>
        <script src="js/vendor/jquery.isotope.min.js"></script>
        <script src="js/vendor/jquery.easypiechart.min.js"></script>
        <script src='js/vendor/jflickrfeed.min.js'></script>
        <script src="js/vendor/jquery.sticky.js"></script>
        <script src='js/vendor/owl.carousel.min.js'></script>
        <script src='js/vendor/jquery.nicescroll.min.js'></script>
        <script src='js/vendor/jquery.fractionslider.min.js'></script>
        <script src='js/vendor/jquery.scrollTo-min.js'></script>
        <script src='js/vendor/jquery.localscroll-min.js'></script>
        <script src='js/vendor/jquery.parallax-1.1.3.js'></script>

        <script src="js/plugins.js"></script>
        <script src="js/main.js"></script>

         <!-- Map Scripts -->
        <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
    </body>
</html>

我不明白,问题出在哪里?有人可以指导哪里找/看?我曾经在stackoverflow和互联网上阅读了几篇文章/博客,但仍然没有得到任何解决方案。 谢谢。

2015年11月5日编辑:

现在我在浏览器上收到错误&#34;没有指定输入文件。&#34;,其中我的nginx错误日志有以下错误:

FastCGI sent in stderr: "PHP message: PHP Warning:  Unknown: failed to open stream: Success in Unknown on line 0
Unable to open primary script: [path] (Success)" while reading response header from upstream

和nginx访问日志有此错误:

GET /index.php HTTP/1.1" 404 56 "-" "Mozilla/5.0 (X11; Linux x86_64) 

1 个答案:

答案 0 :(得分:0)

如何在这里添加index.php?第11行。

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /home/manish/workspace/statistics;
    index **index.php** index.html index.htm;