• nginx-port-Permission-denied


    nginx use 9000 port Permission denied  other port ok

    新架构下web服务需要使用反向代理,将不同的请求转发到不同的service,对应不同的端口。

    nginx.conf 配置如下:

            listen       80 default_server;
            listen       [::]:80 default_server;
            server_name  _;
            root         /usr/share/nginx/html;
    
            # Load configuration files for the default server block.
            include /etc/nginx/default.d/*.conf;
    
            location / {
            }
            include rs.conf;
            include d.conf;
            error_page 404 /404.html;

    rs.conf 和 d.conf 

    location /deliver {
        proxy_set_header Host $host;
        proxy_pass  http://127.0.0.1:9002;
    
    }
    
    
    location /click {
        proxy_set_header Host $host;
        proxy_pass  http://127.0.0.1:9000 ;
      }

    确保 两个proxy_pass 分别可以正常访问,

    通过nginx listen的server 访问请求对应的路径,发现只有click 的路径可正常访问,deliver  的服务,

    经过多次实验,deliver 无论使用 9001 还是9002 均不能访问,对应nginx提示:

    *41 connect() to 127.0.0.1:9002 failed (13: Permission denied) while connecting to upstream, client: 1.2.3.4 ,
    server: _, request: "GET /deliver HTTP/1.1", upstream: "http://127.0.0.1:9002/deliver", host: "35.0.0.86"

    如果把click服务暂停,把deliver 服务启动时候绑定9000 端口则deliver 服务可正常访问,

    因此问题和服务启动端口有关,nginx 无法listen 并且代理转发;

    具体原因和使用的google cloud 安装的镜像版本内核为的 selinux 的配置有关;

    semanage命令是用来查询与修改SELinux默认目录的安全上下文。SELinux的策略与规则管理相关命令:seinfo命令、sesearch命令、getsebool命令、setsebool命令、semanage命令。

    semanage port -l | grep http_port_t
    http_port_t tcp 80, 81, 443, 488, 8008, 8009, 8443, 9000
    As you can see from the output above with SELinux in enforcing mode http is only allowed to bind to the listed ports. The solution is to add the ports you want to bind on to the list
    semanage port -a -t http_port_t -p tcp  9002 

    对selinux 的http 端口增加 9002 ,访问nginx 配置listen 的server +location /deliver 服务终于可以正常访问 。

    tag: "nginx port Permission denied  other port ok"

    9000 service code:

    package main
    
    import (
        "fmt"
        "log"
        "net/http"
    )
    
    func main() {
    
        //http.HandleFunc("/deliver", myHandler)
        http.HandleFunc("/click", clickHandler)
    
        log.Fatal(http.ListenAndServe("127.0.0.1:9000", nil))
    }
    
    func myHandler(w http.ResponseWriter, r *http.Request) {
        fmt.Fprintln(w, "deliver service")
    }
    
    func clickHandler(w http.ResponseWriter, r *http.Request) {
        fmt.Fprintln(w, "hello this is click ")
    }
  • 相关阅读:
    P2765 魔术球问题 网络流二十四题重温
    搬东西 dp
    Q
    P2774 方格取数问题 网络流重温
    2019牛客暑期多校训练1
    E. A Simple Task
    Codeforces Round #575 (Div. 3) 昨天的div3 补题
    自动化测试如何准备测试数据
    金三银四,资深HR给面试者的十大建议
    我的自动化测试之路[转载]
  • 原文地址:https://www.cnblogs.com/lavin/p/nginx-port-Permission-denied.html
Copyright © 2020-2023  润新知