• docker nginx容器 端口配置


    今天在服务器上部署了一个docker的nginx容器,宿主机和容器的端口映射是8181:80
    nginx配置文件如下

    server {
        listen 8181;
    
        server_name docker-test.mydocker.com;
        set $project_path user-api/public;
        set $docker_root /www;
    
        root $docker_root/$project_path;
        index index.php;
        try_files $uri $uri/ /index.php?$query_string;
    
        location ~ \.php$ {
            fastcgi_pass  php72:9000;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $docker_root/$project_path/$fastcgi_script_name;
            include    fastcgi_params;
            if ($http_origin) {
                add_header Access-Control-Allow-Origin $http_origin always;
                add_header Access-Control-Allow-Credentials true always;
                add_header Access-Control-Allow-Headers "Authorization, X-XSRF-TOKEN, Content-Type, Origin, Xmen-Token, Giver-Token" always;
                add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE" always;
            }
        }
    }
    

    访问后一直报错

    curl: (56) Recv failure: Connection reset by peer
    

    一顿研究后发现,nginx配置文件 listen应该是80,而不是8181。外部访问地址是http://docker-test.mydocker.com:8181,但是nginx配置文件是在容器内使用,应该使用容器的端口80,所以把上面的配置改为容器的端口即可

    server {
        listen 80;
    
        server_name docker-test.mydocker.com;
        set $project_path user-api/public;
        set $docker_root /www;
    
        root $docker_root/$project_path;
        index index.php;
        try_files $uri $uri/ /index.php?$query_string;
    
        location ~ \.php$ {
            fastcgi_pass  php72:9000;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $docker_root/$project_path/$fastcgi_script_name;
            include    fastcgi_params;
            if ($http_origin) {
                add_header Access-Control-Allow-Origin $http_origin always;
                add_header Access-Control-Allow-Credentials true always;
                add_header Access-Control-Allow-Headers "Authorization, X-XSRF-TOKEN, Content-Type, Origin, Xmen-Token, Giver-Token" always;
                add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE" always;
            }
        }
    }
    
  • 相关阅读:
    CMS之图片管理(4)
    CMS之图片管理(2)
    CMS:文章管理之控制器
    CMS:文章管理之视图(1)
    CMS:文章管理之视图(3)
    CMS:文章管理之视图(2)
    影响Incremental checkpoint position的条件
    oracle中一个数据文件的最大值(非lob)
    X$KCCLE
    图一时之快:手动释放Linux服务器内存
  • 原文地址:https://www.cnblogs.com/whyly/p/15908547.html
Copyright © 2020-2023  润新知