zoukankan      html  css  js  c++  java
  • nginx配置thinkphp5

    nginx,php,tp框架版本:

    nginx版本:
    [root@z_centos nginx]# /usr/local/nginx/sbin/nginx -h
    nginx version: nginx/1.13.9
    
    tp5版本:
    thinkphp 5.0.18
    
    PHP版本:
    [root@z_centos nginx]# php -v
    PHP 7.2.3 (cli) (built: Mar  8 2018 14:43:32) ( ZTS )
    Copyright (c) 1997-2018 The PHP Group
    Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
        with Zend OPcache v7.2.3, Copyright (c) 1999-2018, by Zend Technologies

    usr/locol/nginx/conf/vhost/www.xxxx.com.conf 配置文件
    主配置文件中使用 include ./vhost/*.conf; 引入即可

    https 443端口配置项:

    server {
            listen       443 ssl;
            server_name www.xxxx.com;
            set $root /usr/local/nginx/webroot/tp5/public;            
            ssl_certificate      /etc/letsencrypt/live/www.xxxx.com/fullchain.pem;
            ssl_certificate_key  /etc/letsencrypt/live/www.xxxx.com/privkey.pem;
            ssl_session_timeout  5m;
            ssl_prefer_server_ciphers on;
            access_log  logs/www.myzb.pw.access.log  main;
         
         if ($http_user_agent ~* "qihoobot|Baiduspider|YoudaoBot|Sosospider|Sogou spider|Sogou web spider|MSNBot|ia_archiver|Tomato Bot") 
          { 
              return 403; 
          } 
    
            location ~ ..(gif|jpg|jpeg|bmp|png|ico|txt|js|css)$
            {
               root $root;
            }
            location / {
                root   $root;
                index  index.php index.html index.htm;
                if ( -f $request_filename) {
                   break;
                }
    
                if ( !-e $request_filename) {
                    rewrite ^(.*)$ /index.php?s=/$1 last;
                }
            }
    
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
            location ~ .+.php($|/) {
            set $script $uri;
                set $path_info "";
                if ($uri ~ "^(.+.php)(/.+)") {
                    set $script $1;
                    set $path_info $2;
                }
            
                fastcgi_pass    unix:/var/run/www/php-cgi.sock;
                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;
                include        fastcgi_params;
                
            }
    
            location ~ /.(ht|svn|git) {
                deny  all;
            }
        }
    http 80端口配置项:
    server {
        listen       80;
        server_name tp510.manzb.top;
        set $root /usr/local/nginx/www/tp510/public;            
        access_log  logs/tp510.manzb.top.access.log  main;
            location ~ ..(gif|jpg|jpeg|bmp|png|ico|txt|js|css)$
            {
               root $root;
            }
        location / {
            root   $root;
            index  index.php index.html index.htm;
            if ( -f $request_filename) {
               break;
            }
    
            if ( !-e $request_filename) {
                rewrite ^(.*)$ /index.php?s=/$1 last;
            }
        }
    
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        location ~ .+.php($|/) {
                 set $script $uri;
            set $path_info "";
            if ($uri ~ "^(.+.php)(/.+)") {
                set $script $1;
                set $path_info $2;
            }
        
            fastcgi_pass    unix:/var/run/www/php-cgi.sock;
            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;
            include        fastcgi_params;
            
        }
    
        location ~ /.(ht|svn|git) {
            deny  all;
        }
    }

    其中:fastcgi_pass之所以使用unix:/var/run/www/php-cgi.sock;配置参数,是因为:http://www.cnblogs.com/manzb/p/8875406.html

    重启nginx时若出现了如下错误:

    nginx: [emerg] unknown log format "proxy_log" in /usr/local/macports/etc/nginx/nginx.conf:147

    解决办法:

    打开nginx.conf,"main"错误是因为丢失了log_format选项,之前把他屏蔽掉了,修改之后问题解决。

    http {
        include       mime.types;
        default_type  application/octet-stream;

        log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for"';

  • 相关阅读:
    poj2752Seek the Name, Seek the Fame【kmp next数组应用】
    poj1961Period【kmp next数组】
    poj2406(kmp next数组)
    KMP原理
    0529
    0428
    2045年4月25日
    0421
    黄金连分数【大数】
    学习linux内核时常碰到的汇编指令(1)
  • 原文地址:https://www.cnblogs.com/deverz/p/8876323.html
Copyright © 2011-2022 走看看