WebStack-Laravel+nginx搭建个人网址导航

  • 环境
    centos 7.8
    nginx 1.16.1(自行编译安装)
    mysql 8.0.16(自行编译安装)
    php 7.2.12(自行编译安装)
    Composer 1.10.21(直接用yum安装)

  • 下载程序包
    mkdir /data/www/www.fafdy.com/
    cd /data/www/www.fafdy.com/
    git clone https://github.com/hui-ho/WebStack-Laravel.git
    或者git clone https://gitee.com/feko/WebStack-Laravel.git
    cd WebStack-Laravel
  • 安装依赖(可能有报错,提示连接数据库不上)

    composer install
  • 创建数据库和用户

    mysql -uroot -p123456 -e "create database wls2021;"
    mysql -uroot -p123456 -e "create user ‘wls2021‘@‘127.0.0.1‘ identified with mysql_native_password by ‘wls2021‘;"
    mysql -uroot -p123456 -e "grant all on  wls2021.* to ‘wls2021‘@‘127.0.0.1‘;"
  • 编辑配置文件

    cp .env.example .env
    vi .env
    ...省略
    DB_DATABASE=wls2021
    DB_USERNAME=wls2021
    DB_PASSWORD=wls2021
    ...省略
  • 生成KEY

    php artisan key:generate
    >>>>xtnlYUu+K3gi9DmhF/MfB1lIbuLAncQsF2oNJys=
  • 加入KEY到app.php

    vi   config/app.php
    ‘key‘ => env(‘APP_KEY‘,‘xtnlYUu+K3gi9DmhF/MfB1lIbuLAncQsF2oNJys=‘),
  • 再次安装依赖

    composer install
  • 导入数据库

    php artisan migrate:refresh --seed
  • 配置nginx

    cat www.fafdy.com.conf
    server {  
    listen 80;
    server_name  www.fafdy.com;
    return 307 https://www.fafdy.com$request_uri; 
    }
    server {
    listen 443 ssl;
    server_name www.fafdy.com;  #域名
    ssl_certificate  /etc/letsencrypt/live/www.fafdy.com/fullchain.pem;
    ssl_certificate_key  /etc/letsencrypt/live/www.fafdy.com/privkey.pem;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers HIGH:!aNULL:!MD5;
    access_log /data/logs/www.fafdy.com.acc.log access;
    error_log /data/logs/www.fafdy.com.err.log;
    root /data/www/www.fafdy.com/WebStack-Laravel/public;  #项目的public目录
    index index.html index.htm index.php;
    location ~ .*\.(php|php5|jsx)?$ 
    {
    #   fastcgi_pass  127.0.0.1:9000;
        fastcgi_pass  unix:/data/tmp/php-fpm.sock;
        fastcgi_index index.php;
        fastcgi_connect_timeout 120s;
        fastcgi_send_timeout 120s;
        fastcgi_read_timeout 120s;
        include fastcgi.conf;
    }
    
    location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)
    {
        return 404;
    }    
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
    if (!-d $request_filename)
    {
        rewrite ^/(.+)/$ /$1 permanent;
    }
    if ($request_uri ~* index/?$)
    {
        rewrite ^/(.*)/index/?$ /$1 permanent;
    }
    if (!-e $request_filename)
    {
          rewrite ^/(.*)$ /index.php?/$1 last;
          break;
    }
    location = /50x.html {
          root   html;
    }
    }
    chmod www.www /data/www/www.fafdy.com -R
  • 重启nginx和php-fpm
  • 附加-强制使用https
    vi app/Providers/AppServiceProvider.php
    ...
    public function boot()
    {
        \URL::forceScheme(‘https‘); ##加入这行
    ...
  • WebStack-Laravel+nginx搭建个人网址导航

    上一篇:8 HTTP 的请求方法


    下一篇:浏览器输入url后发生了什么?