6

LNMP + Laravel

 3 years ago
source link: https://arminli.com/lnmp-laravel/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

LNMP + Laravel

June 05, 2018

本文是在 LNMP 1.5 环境下部署 Laravel 的教程,其中 LNMP 使用 https://lnmp.org 的一键安装包。

打开 proc_open

laravel 需要 procopen 等函数,需要在 /usr/local/php/etc/php.ini 中的 `disablefunctions删掉procopenprocget_status,保存后lnmp php-fpm restart` 重启 php。

NGINX 配置

在 nginx 的配置中,设置了强制跳转 https,也包含了伪静态的重写文件。

server
    {
        listen 80;
        #listen [::]:80;
        server_name freecandy.one www.freecandy.one;
        rewrite ^(.*)$ https://freecandy.one$1 permanent;

    }

server
    {
        listen 443 ssl http2;
        #listen [::]:443 ssl http2;
        server_name freecandy.one ;
        index index.php index.htm index.html default.html default.htm default.php;
        root  /home/wwwroot/freecandy.one/public;
        ssl on;
        ssl_certificate /usr/local/nginx/conf/ssl/freecandy.one/fullchain.cer;
        ssl_certificate_key /usr/local/nginx/conf/ssl/freecandy.one/freecandy.one.key;
        ssl_session_timeout 5m;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;
        ssl_ciphers "EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5";
        ssl_session_cache builtin:1000 shared:SSL:10m;
        ssl_dhparam /usr/local/nginx/conf/ssl/dhparam.pem;

        include rewrite/laravel.conf;

        location ~ \.php$ {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass  unix:/tmp/php-cgi.sock;
            fastcgi_index index.php;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }

        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }

        location ~ /.well-known {
            allow all;
        }

        location ~ /\.
        {
            deny all;
        }

        access_log off;

    }

通过 chown -R www:www freecandy.one 将网站目录的权限从 root 修改为 www。默认的路径在 /home/wwwroot/freecandy.one/

删掉防跨目录

在 Thinkphp、codeigniter、Laravel 等框架下,网站目录一般是在 public 下,但是 public 下的程序要跨目录调用 public 上级目录下的文件,因为 LNMP 默认是不允许跨目录访问的,所以都是必须要将防跨目录访问的设置去掉,有时候这些框架类的程序提示 500 错误也可能是这个问题引起的。

LNMP 1.4 上如果不想用防跨目录或者修改.user.ini 的防跨目录的目录还需要将 /usr/local/nginx/conf/fastcgi.conf 里面的 fastcgiparam PHPADMINVALUE “openbasedir=$document_root/:/tmp/:/proc/”; 在该行行前添加 # 或删除改行,需要重启 nginx。

LNMP 1.4 上也可以直接使用 lnmp1.4/tools/ 目录下的 ./removeopenbasedir_restriction.sh 进行移除。

删掉网站目录时,需要先 chattr +i /网站目录/.user.ini 之后即可删除。

Reference

  1. https://lnmp.org/faq/lnmp-vhost-add-howto.html

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK