nginx不解析php代碼;解決方案

來源:互聯網
上載者:User
安裝:sudo apt-get install nginx php7.0-fpm mysql-server-5.6 php7.0-mysql然後改設定檔,php的設定檔不用改就能用,nginx的設定檔不行,預設情況下是不支援php CGI的,所以得改一下:vim /etc/nginx/sites-available/default找到##location ~ \.php$ {# include snippets/fastcgi-php.conf;## # With php5-cgi alone:# fastcgi_pass 127.0.0.1:9000;# # With php5-fpm:# fastcgi_pass unix:/var/run/php5-fpm.sock;#}改成location ~ \.php$ {include snippets/fastcgi-php.conf;# With php5-cgi alone:#fastcgi_pass 127.0.0.1:9000;# With php5-fpm:fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;}大概意思就是所有以 .php 積極結尾的檔案都傳給php7.0-fpm去處理,處理完了把結果發給nginx,然後再由nginx發給客戶機然後重啟一下服務:systemctl restart nginxsystemctl restart php7.0-fpmsystemctl restart mysql就好啦預設的網站根目錄在/var/www/html/(可以通過nginx的設定檔裡root 的那行改)題主要是想搭wordpress之類的話,要把index.php當做首頁的就是把nginx設定檔中的index index.html index.htm index.nginx-debian.html;改成 index.php

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.