Ubuntu16.04配置nginx
1:=>首先更新资源包
sudo apt-get update
2:=>安装mysql数据库
sudo apt-get install mysql-server
3:=>安装nginx服务器
sudo apt-get install nginx
4:=>安装php以及扩展模块
sudo apt-get install php7.0-mysql php7.0-mbstring php7.0-fpm
//添加常用扩展模块
sudo apt-get install php7.0-fpm php7.0-mysql php7.0-common php7.0-curl php7.0-cli php7.0-mcrypt php7.0-mbstring php7.0-dom php7.0-gd
5:=>修改nginx配置文件&开启php解析模块
-ubuntu:/etc/nginx/sites-available$ sudo vim default
配置信息如下-----------
location ~ \.php$ {
#include snippets/fastcgi-php.conf;
#With php7.0-cgi alone:
#fastcgi_pass 127.0.0.1:9000;
#With php7.0-fpm:
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
配置laravel项目,配置文件如下:
-ubuntu:/etc/nginx/sites-available$ sudo vim default
配置信息:
root /var/www/html/student/public;
index index.php index.html index.htm index.nginx-debian.html;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
#try_files $uri $uri/ =404;
rewrite ^/(.*)$ /index.php?_url=/$1;
}
location ~ \.php$ {
#include snippets/fastcgi-php.conf;
#
## With php7.0-cgi alone:
#fastcgi_pass 127.0.0.1:9000;
## With php7.0-fpm:
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
#配置Nginx动静分离,定义的静态页面直接从Nginx发布目录读取。
location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$
{
root /var/www/html/student/public;
#expires定义用户浏览器缓存的时间为7天,如果静态页面不常更新,可以设置更长,这样可以节省带宽和缓解服务器的压力
expires 7d;
}
//重启服务器
sudo /etc/init.d/nginx restart