tp5.1 非80端口 路由问题

#  power by www.php.cn
#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


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"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;
    #tcp_nodelay on;
  fastcgi_connect_timeout 300;
  fastcgi_send_timeout 300;
  fastcgi_read_timeout 300;
  fastcgi_buffer_size 128k;
  fastcgi_buffers 4 128k;
  fastcgi_busy_buffers_size 256k;
  fastcgi_temp_file_write_size 256k;

  #gzip  on;
  gzip on;
  gzip_min_length  1k;
  gzip_buffers     4 32k;
  gzip_http_version 1.1;
  gzip_comp_level 2;
  gzip_types       text/plain application/x-javascript text/css application/xml;
  gzip_vary on;
  gzip_disable "MSIE [1-6].";

  server_names_hash_bucket_size 128;
  client_max_body_size     100m; 
  client_header_buffer_size 256k;
  large_client_header_buffers 4 256k;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;
        root    "C:/phpStudy/PHPTutorial/WWW/tp5/public";
        index index.html index.php;
        set $root "C:/phpStudy/PHPTutorial/WWW/tp5/public";
        location / {
            #重写url 为了隐藏tp5中的index.php
            if ( !-e $request_filename) {
                #将url中server_name之后的部分与 /tp5/public/* 匹配 如果匹配则改写URl为/tp5/public/index.php/*
                rewrite ^/(.*)$ /index.php/$1 last;
                break;
            }
        }
      
        #pathinfo配置 使支持tp5的标准url
        location ~ .+\.php($|/) {
            fastcgi_pass   127.0.0.1:9000;    #不支持的改为:127.0.0.1:9000;
            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 ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
            expires -1;
            access_log off;
        }
        location ~ .*\.(js|css)?$ {
            expires -1;
            access_log off;
        }
        location ~ /\.ht {
            deny all;
        }
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443;
    #    server_name  localhost;

    #    ssl                  on;
    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_timeout  5m;

    #    ssl_protocols  SSLv2 SSLv3 TLSv1;
    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers   on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

include vhosts.conf;
#include tp.conf;

}





 phpStudy 上配置的https://www.jianshu.com/p/7d9e2b6168ec,亲测有效

今天在腾讯云上面搞了一下8080端口,在大神的帮助下,解决了若干问题

1.nginx 配置 api.conf

server {
    listen 80; //8080
    access_log /data/wwwlogs/tp_nginx.log combined;
    index index.html index.htm index.php;
    root /data/wwwroot/default/purenfort/public; // 现在是/data/wwwroot/default/purenfort-api/public; sudo iptables -I INPUT -p tcp --dport 8080 -j ACCEPT


    #error_page 404 /404.html;
    #error_page 502 /502.html;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }


    location ~ \.php(.*)$ { # 正则匹配.php后的pathinfo部分
        fastcgi_pass unix:/dev/shm/php-cgi.sock;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $1;   # 把pathinfo部分赋给PATH_INFO变量
        include fastcgi.conf;
    }

    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
        expires -1;
        access_log off;
    }
    location ~ .*\.(js|css)?$ {
        expires -1;
        access_log off;
    }
    location ~ /\.ht {
        deny all;
    }

}

2服务器开启防火墙

sudo iptables -I INPUT -p tcp --dport 8080 -j ACCEPT

3.腾讯云上面开启白名单 端口

接下来闲的蛋疼,发现了一个问题 ,在route.php中写了

Route::rule('login', 'index/login/index');

然后url访问 http://140.143.132.167:8080/login.html 没有问题,当从其他页面跳转回来的时候,发现rule方法竟然把端口号吃了。解决方案/thinkphp/library/think/route/RuleItem.php中 getDomain 方法替换成$_SERVER['HTTP_HOST']

/**
     * 设置路由标识 用于URL反解生成
     * @access protected
     * @param  bool     $first   是否插入开头
     * @return void
     */
    protected function setRuleName($first = false)
    {    
        // dump($this->name);
        if ($this->name) {
            $vars = $this->parseVar($this->rule);
            $name = strtolower($this->name);

            if (isset($this->option['ext'])) {
                $suffix = $this->option['ext'];
            } elseif ($this->parent->getOption('ext')) {
                $suffix = $this->parent->getOption('ext');
            } else {
                $suffix = null;
            }

            // $value = [$this->rule, $vars, $this->parent->getDomain(), $suffix, $this->method];
            $value = [$this->rule, $vars, $_SERVER['HTTP_HOST'], $suffix, $this->method];
            if($_SERVER['SERVER_PORT'] == '80'){
                $value = [$this->rule, $vars, $this->parent->getDomain(), $suffix, $this->method];
            }else{
                $value = [$this->rule, $vars, $_SERVER['HTTP_HOST'], $suffix, $this->method];
            }

            // $value[2] = '140.143.136.167:8080';
            Container::get('rule_name')->set($name, $value, $first);
            Container::get('rule_name')->setRule($this->rule, $this);
        }
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值