lnmp(ubuntu+nginx+mysql+php7.0[laravel]) + https服务搭建

1,ubuntu  -- 不用多说,安装方式 网上一大堆 云服务器直接更换系统盘 就OK

2,更新ubuntu

sudo apt-get update

sudo apt-get upgrade

3,安装nginx,php,php-mbstaring,phpunit,zip,composer,spawn-fcgi,php-mysql,php-gd,php-curl,php-redis

sudo apt-get install nginx php7.0 php-mbstring phpunit zip composer spawn-fcgi php-mysql php-gd php-curl php-redis

注意:某些拓展需要重启后才可生效 (建议重启--保险起见)

reboot(重启命令)

4,切换至nginx根目录下composer安装laravel

cd /var/www/html

composer global require "laravel/installer"

composer create-project laravel/laravel --prefer-dist blog

----给予权限755

sudo chmod -R 755 /var/www/html/blog

5,配置nginx 已支持 -- php

sudo vi /etc/nginx/sites-available/default

#站点配置

server {

#监听80端口

listen 80;

#项目路径

root /var/www/html/blog/public;

#主机名(默认不需要动)

server_name _;

#root根目录下的配置

location / {

index index.php index.html index.htm index.nginx-debian.html;

#在这个地方加上index.php

#try_files $uri $uri/ =404;

try_files $uri $uri/ /index.php?$query_string;

#修改以便支持laravel路由重组

autoindex on;

#开启目录浏览功能

autoindex_exact_size off;

#关闭详细文件大小统计,让文件大小以MB单位显示 on(开启以b显示)

autoindex_localtime on;

#开启 以服务器本地时区 显示文件的修改日期

}

location ~ \.php$ {

#include snippets/fastcgi-php.conf;

#php解析9000端口

fastcgi_pass 127.0.0.1:9000;

#执行index.php

fastcgi_index index.php;

#启动执行指定的目录

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

#注意$document_root 是父级 root指定的目录 也可以换成绝对路径如下  == 关系==  http > server > location

#fastcgi_param SCRIPT_FILENAME /var/www/html/blog/public$fastcgi_script_name;

#引入启动

include fastcgi_params;

}

#路由重写部分

location ~ /\.ht {

deny all;

}

}

#多站点配置建议方案(例下)

#include /etc/nginx/vhosts/*

#某文件架下的多个站点文件 配置多个server即可

6,使用spawn-fcgi启动9000 以便支持 php

spawn-fcgi -a 127.0.0.1 -p 9000 -C 10 -u www-data -f /usr/bin/php-cgi

# -a 127.0.0.1 : PHP FastCGI 绑定IP地址

# -p 9000 : PHP FastCGI 指定端口

# -u www : PHP FastCGI 用户名

# -g www : PHP FastCGI 用户组

# -f /usr/bin/php-cgi : 指向 PHP fastcgi

可将该命令写入/etc/rc.local中的exit 0的上方,以便于开机直接启动9000端口 开启php支持

7,重启nginx

sudo server nginx stop

#停止nginx

sudo server nginx start

#开启nginx

sudo server nginx restart

#重启nginx

8,https配置 -- 阿里云购买 -- 免费证书

注意 -- 在申请过程中:选择DNS并填写 -- 好自身的域名 -- 只有申请时被填写的域名所颁发的证书 才可以被生效 否则不会被受信任

#HTTP

server {

listen 80;

server_name sstmov.com;

# return 301 https://$server_name$request_uri;

# rewrite ^/(.*) https://ssl.lanbing.org/$1 permanent; #关键代码仔细比较两者的跳转的区别

#告诉浏览器有效期内只准用 https 访问

add_header Strict-Transport-Security max-age=15768000;

#永久重定向到 https 站点

return 301 https://$server_name$request_uri;

}

#SSL

server {

listen 443;

server_name localhost;

ssl on;

root /var/www/html;

index index.html index.htm index.nginx-debian.html;

ssl_certificate  cert/214023913850896.pem;

ssl_certificate_key  cert/214023913850896.key;

# ssl_certificate  (磁盘目录/订单号2.pem -- 购买下载证书的.pem 文件);

# ssl_certificate_key (磁盘目录/订单号2.key -- 购买下载证书的.key 文件);

ssl_session_timeout 5m;

ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;

ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

ssl_prefer_server_ciphers on;

location / {

root /var/www/html;

index index.html index.htm index.nginx-debian.html;

}

}

你可能感兴趣的:(lnmp(ubuntu+nginx+mysql+php7.0[laravel]) + https服务搭建)