Ubuntu 安装配置 nginx

作者:任明旭
链接:https://www.zhihu.com/question/46241604/answer/100788789
来源:知乎
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

第一句当然是先安装:
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 nginx
systemctl restart php7.0-fpm
systemctl restart mysql
就好啦默认的网站根目录在/var/www/html/(可以通过nginx的配置文件里root 的那行改)
题主要是想搭wordpress之类的话,要把index.php当做主页的
就是把nginx配置文件中的
index index.html index.htm index.nginx-debian.html;
改成 index.php

原文地址:https://www.cnblogs.com/mouseleo/p/8763598.html