'nginx permission 에러'에 해당되는 글 1건

  1. 2018.02.22 Nginx 리버스 프록시(포트포워딩), nginx permission 에러
2018. 2. 22. 19:12

먼저 Nginx의 폴더 구조에 대해서 설명하겠다.


/etc/nginx   : 여기는 설정파일들이있음.

/etc/nginx/conf.d  : 기본설정 파일이 들어있음.

/usr/share/nginx/html : 기본 띄우는 html파일폴더

/var/log/nginx : 로그파일들이다.




/etc/nginx/nginx.conf 가 기본 설정 파일임.



여기 안에 보면, 

> vi nginx.conf


include 가 있다.


# For more information on configuration, see:

#   * Official English Documentation: http://nginx.org/en/docs/

#   * Official Russian Documentation: http://nginx.org/ru/docs/


user nginx;

#user root;

worker_processes auto;

error_log /var/log/nginx/error.log;

pid /var/run/nginx.pid;


# Load dynamic modules. See /usr/share/nginx/README.dynamic.

include /usr/share/nginx/modules/*.conf;


events {

    worker_connections  1024;

}



http {

    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  /var/log/nginx/access.log  main;


    sendfile            on;

    tcp_nopush          on;

    tcp_nodelay         on;

    keepalive_timeout   65;

    types_hash_max_size 2048;


    include             /etc/nginx/mime.types;

    default_type        application/octet-stream;


    # Load modular configuration files from the /etc/nginx/conf.d directory.

    # See http://nginx.org/en/docs/ngx_core_module.html#include

    # for more information.

    include /etc/nginx/conf.d/*.conf;

    include /etc/nginx/site-available/*.conf;


}




include /etc/nginx/conf.d/*.conf 

는 conf.d폴더의 .conf로 끝나는 파일은 다 저 자리에 넣는거다.


그래서, 관리하는 사이트 만 밑에처럼 작성해서 test.conf 이런식으로 넣어 놓으면 각 서버 정보가 추가되는거다.




server {

    listen 80;


    server_name test.com;

    root /usr/share/nginx/html;


    location / {

        include /etc/nginx/uwsgi_params;

        proxy_pass http://127.0.0.1:3000;

        proxy_http_version 1.1;

        proxy_set_header Upgrade $http_upgrade;

        proxy_set_header Connection 'upgrade';

        proxy_set_header Host $host;

        proxy_cache_bypass $http_upgrade;

    }

}



자, 위에꺼는 80 포트, test.com으로 들어오면, 

로컬호스트 3000포트로 보내라는 건데,


여기서 계속 에러가 뜨는거다..


2018/02/22 09:40:25 [crit] 25667#0: *6 connect() to 127.0.0.1:3000 failed (13: Permission denied) while connecting to upstream, client: 112.111.11.11, server: test.com, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:3000/", host: "test.com"


이런식의 로그가 게속 뜨는거다.


여기서 미치는거다. 권한 문제인가 해서...폴더들 권한 등등 다 넣었는데, 안되는거다.....


아무리 찾아도 없고........


그러다가 방화벽쪽 문제인거 같더라.


SELinux에서 포트포워딩을 막는거 같아서, 




$setsebool httpd_can_network_connect on

위에처럼 해주니까, 바로 프록시포트가 먹힌다.


진짜 이거 찾는데, 엄청 오래 걸렸다!!




<https://stackoverflow.com/questions/23948527/13-permission-denied-while-connecting-to-upstreamnginx

 여기 참조>


I’ve run into this problem too. Another solution is to toggle the SELinux boolean value for httpd network connect to on (Nginx uses the httpd label).

setsebool httpd_can_network_connect on

To make the change persist use the -P flag.

setsebool httpd_can_network_connect on -P

You can see a list of all available SELinux booleans for httpd using

getsebool -a | grep httpd





Posted by Tyson