1. 程式人生 > >lnmp安裝包配置tp5專案所需要的準備

lnmp安裝包配置tp5專案所需要的準備

配置 *.conf 檔案

  • 新增配置檔案目錄

  • # 開啟nginx.conf配置檔案目錄
    cd /usr/local/nginx/conf
    # 新增配置目錄
    vim nginx.conf
    user  www www;
    
    worker_processes auto;
    
    error_log  /home/wwwlogs/nginx_error.log  crit;
    
    pid        /usr/local/nginx/logs/nginx.pid;
    
    #Specifies the value for maximum file descriptors that can be opened by this
    process. worker_rlimit_nofile 51200; events { use epoll; worker_connections 51200; multi_accept on; } http { include mime.types; default_type application/octet-stream; server_names_hash_bucket_size 128; client_header_buffer_size 32k; large_client_header_buffers
    4 32k; client_max_body_size 50m; sendfile on; tcp_nopush on; keepalive_timeout 60; tcp_nodelay on; fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; fastcgi_buffer_size 64k; fastcgi_buffers 4
    64k; fastcgi_busy_buffers_size 128k; fastcgi_temp_file_write_size 256k; gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.1; gzip_comp_level 2; gzip_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml application/xml+rss; gzip_vary on; gzip_proxied expired no-cache no-store private auth; gzip_disable "MSIE [1-6]\."; #limit_conn_zone $binary_remote_addr zone=perip:10m; ##If enable limit_conn_zone,add "limit_conn perip 10;" to server section. server_tokens off; access_log off; server { listen 80 default_server; #listen [::]:80 default_server ipv6only=on; server_name _; index index.html index.htm index.php; root /home/wwwroot/default; #error_page 404 /404.html; # Deny access to PHP files in specific directory #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; } include enable-php.conf; location /nginx_status { stub_status on; access_log off; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; } location ~ .*\.(js|css)?$ { expires 12h; } location ~ /.well-known { allow all; } location ~ /\. { deny all; } access_log /home/wwwlogs/access.log; } # 此處新增配置檔案目錄 # 本檔案在 /usr/local/nginx/conf/nginx.conf # 配置目錄在 /usr/local/nginx/conf/vhost/配置檔案 # *.conf 使用正則表示式匹配該配置檔案的目錄 include vhost/*.conf; }

     

  • 記得把預設的serverl裡的內容加上#都註釋掉,不然網頁開啟還是在預設頁面裡
  • 修改vhost中的配置檔案

  • 使用 lnmp1.5一鍵安裝包 新增虛擬機器主機會自動生成配置檔案 
    例如:網站域名.conf -> test.baidu.com.conf
  • server
        {
            listen 80;
            server_name test.baidu.com;
            index index.html index.htm index.php default.html default.htm default.php;
            #根目錄設定到Public下
            root  /home/wwwroot/test.baidu.com/public;
    
    
            #=======================================
            # 新增內容部分
    
            #定義變數
            set $root /home/wwwroot/test.baidu.com/public;
    
            location ~ [^/]\.php(/|$)
            {
                try_files $uri =404;
                fastcgi_pass  unix:/tmp/php-cgi.sock;
                fastcgi_index index.php;
                #設定PATH_INFO
                fastcgi_split_path_info ^((?U).+.php)(/?.+)$;
                fastcgi_param PATH_INFO $fastcgi_path_info;
                fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
                fastcgi_param SCRIPT_FILENAME $root$fastcgi_script_name;
                #引入fastcgi配置
                include fastcgi.conf;
            }
    
            #從URL中去掉index.php入口檔案
            location /
            {
                if (!-e $request_filename) {
                    rewrite  ^(.*)$  /index.php?s=/$1  last;
                    break;
                }
            }
    
            # 新增內容結束
            #==================================
            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;
        }

     

  • 修改 fastcgi.conf 中的配置檔案

  • # 進入 fastcgi.conf 檔案目錄
    cd /usr/local/nginx/conf
    # 修改 fastcgi.conf 配置檔案
    vim fastcgi.conf
    fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
    fastcgi_param  QUERY_STRING       $query_string;
    fastcgi_param  REQUEST_METHOD     $request_method;
    fastcgi_param  CONTENT_TYPE       $content_type;
    fastcgi_param  CONTENT_LENGTH     $content_length;
    
    fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
    fastcgi_param  REQUEST_URI        $request_uri;
    fastcgi_param  DOCUMENT_URI       $document_uri;
    fastcgi_param  DOCUMENT_ROOT      $document_root;
    fastcgi_param  SERVER_PROTOCOL    $server_protocol;
    fastcgi_param  REQUEST_SCHEME     $scheme;
    fastcgi_param  HTTPS              $https if_not_empty;
    
    fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
    fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;
    
    fastcgi_param  REMOTE_ADDR        $remote_addr;
    fastcgi_param  REMOTE_PORT        $remote_port;
    fastcgi_param  SERVER_ADDR        $server_addr;
    fastcgi_param  SERVER_PORT        $server_port;
    fastcgi_param  SERVER_NAME        $server_name;
    
    # PHP only, required if PHP was built with --enable-force-cgi-redirect
    fastcgi_param  REDIRECT_STATUS    200;
    # 初始化配置檔案
    # fastcgi_param PHP_ADMIN_VALUE "open_basedir=$document_root/:/tmp/:/proc/";
    #===========================================
    #新增內容
    # 開放目錄訪問許可權(因為根目錄設定到public下導致框架訪問上級目錄許可權不夠)
    fastcgi_param PHP_ADMIN_VALUE "open_basedir=/home/wwwroot/:/tmp/:/proc/";

     

  • 修改 php.ini 中的配置檔案

  • # 進入 php.ini 檔案目錄
    cd /usr/local/php/etc
    # 修改 php.ini 配置檔案
    vim php.ini
    # 修改內容
    cgi.fix_pathinfo = 1

     

  • 修改完成,重啟lnmp1.5

  • lnmp restart

     

  • 解決TP5許可權不足問題

  • 簡單粗暴方法一

  • # 進入 TP5 根目錄
    cd /home/wwwroot/test.baidu.com
    # 輸入命令
    chmod -R 777 runtime

     

  • 安全方法二

  • # 進入 TP5 根目錄
    cd /home/wwwroot/test.baidu.com
    # 輸入命令
    chown -R www runtime

    轉自:https://blog.csdn.net/wangartorange/article/details/81052353

  • 還可以看一下:https://blog.csdn.net/u010474681/article/details/80722173