Laradock + tp5 + nginx 配置虚拟机域名始终跳转首页/502报错

laradock默认配置文件如下:
配置运用于本地windows+phpstudy 部署的laravel项目未出现问题,如下:
server {
 
    listen 80;
    listen [::]:80;
 
    server_name blog.test;
    root /var/www/blog/public;
    index index.php index.html index.htm;
 
    location / {
         try_files $uri $uri/ /index.php$is_args$args;
    }
 
    location ~ \.php$ {
        try_files $uri /index.php =404;
        fastcgi_pass php-upstream;
        fastcgi_index index.php;
        fastcgi_buffers 16 16k;
        fastcgi_buffer_size 32k;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        #fixes timeouts
        fastcgi_read_timeout 600;
        include fastcgi_params;
    }
 
    location ~ /\.ht {
        deny all;
    }
 
    location /.well-known/acme-challenge/ {
        root /var/www/letsencrypt/;
        log_not_found off;
    }
}

 

 
但配置到laradock中,始终跳转到首页,多番查找原因,最终发现是未正确配置nginx pathinfo规则,修改后的配置文件如下。
 
ps:修改过程中出现502,解决办法:fastcgi_pass 127.0.0.1:9000;
====修改为====>
fastcgi_pass php-upstream;
 
在docker容器中,fastcgi_pass后要跟上php-fpm容器的内容ip地址,如上。
 
接下来,回到原来的问题上,原来的nginx配置如下,去掉 【$】 符号,问题就解决了。
 
server {
 
    listen 80;
    listen [::]:80;
 
    server_name api.52ddtestoop.cn;
    root /var/www/forecast_api/public;
    index index.php index.html index.htm;
 
    #location / {
    #    try_files $uri $uri/ /index.php$is_args$args;
    #}
 
#去掉$符号
    location ~ .+\.php($|/) {
        try_files $uri /index.php =404;
        fastcgi_pass php-upstream;
        fastcgi_index index.php;
        fastcgi_buffers 16 16k;
        fastcgi_buffer_size 32k;
        fastcgi_param PATH_INFO $fastcgi_path_info;#新加第二句
        #fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        #fixes timeouts
        fastcgi_read_timeout 600;
        #include fastcgi_params;
        include        fastcgi.conf;
    }
    try_files $uri $uri/ @rewrite;
    location @rewrite {
        rewrite ^/(.*)$ /index.php?s=$1;
    }
 
    #location ~ /\.ht {
    #   deny all;
    #}
 
    #location /.well-known/acme-challenge/ {
    #    root /var/www/letsencrypt/;
    #    log_not_found off;
    #}
}

 

 
修改整理:
server {
        listen 80;
        listen [::]:80;
 
        server_name api.52ddtest.cn admin.52ddtest.cn;
        root  /var/www/api_test/public;
 
        index index.html index.php;
        location ~ .+\.php($|/) {
                root           /var/www/api_test/public;
                fastcgi_pass   php-upstream;
                fastcgi_index  index.php;
                fastcgi_param  PATH_INFO  $fastcgi_path_info;
                include        fastcgi.conf;
            }
 
        try_files $uri $uri/ @rewrite;
        location @rewrite {
            rewrite ^/(.*)$ /index.php?s=$1;
        }
    }

 

 
 
TP5路由配置:
 
// 动态注册域名的路由规则
//Route::domain('api',[
// ':v/:controller/:action'=>'api/:v.:controller/:action',
//]);
 
//绑定路由规则
//return [
// '__domain__' => [
// 'api' => [
// ':v/:controller/:action'=>'api/:v.:controller/:action',
// ],
// 'admin' => 'admin',
// 'cps' => 'cps',
// ],
//];
 
//绑定到闭包函数
Route::domain('api',function(){
Route::rule(':v/:controller/:action','api/:v.:controller/:action');
// return ['bind'=>'module','module'=>'blog'];
});

 

  • 查看docker内容器的内网ip地址:
 
docker exec [OPTIONS] CONTAINER COMMAND [ARG...]
 
e.g.
docker exec -it 836  bash          进入容器 836为这个容器的id 
cat /etc/hosts               查看容器的ip
 
 
posted @ 2020-02-27 23:26  yokooo  阅读(1037)  评论(0编辑  收藏  举报