2017-06-22 96 views
0

我試過連續幾天來配置上Openshift運行nginx的容器中,到現在爲止,並沒有得到它的工作。運行Nginx的作爲Openshift非root用戶和偵聽端口80

我讀過有關使用非root用戶對secuity原因。然而,無論是根還是非root用戶,openshift不允許我在端口80

2017/06/22 21:18:57 [emerg] 1#1: bind() to 0.0.0.0:80 failed (13: Permission denied) 
nginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied) 

創建容器中的綁定在我的本地機器,我可以成功綁定到容器更高的端口(8081爲例如),然後在主機中創建一個訪問映射(docker run --rm -d -p 9000:8081 mynginx)。通過這種方式,我可以成功地訪問主機地址localhost:9000上的網站,但我沒有意識到我可以在openshit上實現類似的功能。

我希望我可以部署我的圖像與非root用戶和nginx監聽較高的端口(8081),在同一時間openshift轉發所有傳入服務器的端口80流量到端口8081的容器(nginx )。我目前的設置如下:

Dockerfile:

FROM nginx:alpine 

COPY nginx.conf /etc/nginx/nginx.conf 
COPY dist /usr/share/nginx/html 

RUN chmod -R 777 /var/log/nginx /var/cache/nginx /var/run \ 
    && chgrp -R 0 /etc/nginx \ 
    && chmod -R g+rwX /etc/nginx \ 
    && rm /etc/nginx/conf.d/default.conf 

EXPOSE 8081 

和我的nginx.conf文件:

worker_processes 4; 
error_log /var/log/nginx/error.log warn; 
pid  /var/run/nginx.pid; 

events { worker_connections 1024; } 

http { 

    ssl_session_cache shared:SSL:10m; 
    ssl_session_timeout 30m; 

    #See http://blog.argteam.com/coding/hardening-node-js-for-production-part-2-using-nginx-to-avoid-node-js-load 
    proxy_cache_path  /var/cache/nginx levels=1:2 keys_zone=one:8m max_size=3000m inactive=600m; 
    proxy_temp_path   /var/tmp; 
    include     mime.types; 
    default_type   application/octet-stream; 
    sendfile    on; 
    keepalive_timeout  65; 

    gzip     on; 
    gzip_comp_level   6; 
    gzip_vary    on; 
    gzip_min_length   1000; 
    gzip_proxied   any; 
    gzip_types    text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript; 
    gzip_buffers 16 8k; 

    server { 
    listen  8081; 
    server_name localhost; 

    location/{ 
     root /usr/share/nginx/html; 
     index index.html; 
     expires -1; 
     add_header Pragma "no-cache"; 
     add_header Cache-Control "no-store, no-cache, must-revalidate, post-check=0, pre-check=0"; 
     try_files $uri$args $uri$args/ $uri $uri/ /index.html =404; 
    } 
    } 
} 

觀測數據:部署在管道過程中自動發生。我正在使用來自gitlab的custom docker image,負責部署到openshift。此自定義圖像使用openshift origin CLI來處理部署。

+0

Stack Overflow是用於編程和發展問題的站點。這個問題似乎與題目無關,因爲它不涉及編程或開發。請參閱幫助中心的[我可以詢問哪些主題](http://stackoverflow.com/help/on-topic)。也許[超級用戶](http://superuser.com/)或[Unix&Linux堆棧交換](http://unix.stackexchange.com/)會是一個更好的地方。 – jww

+0

另請參見[允許非根過程綁定到端口80和443?(https://superuser.com/q/710253/173513)上超級用戶。 – jww

+0

nginx錯誤消息不適合nginx配置文件。 shell'nginx -V'中'oc debug dc/your-dc'的輸出是什麼 – Aleksandar

回答

3

使用8080端口監聽。當您在OpenShift之外公開Web服務器的服務時,外部路由默認情況下會默認使用端口80,並確保流量在內部路由到Web服務器的端口8080。如果將服務內部聯繫到OpenShift,您需要通過端口8080聯繫它。

此外,要知道,一個S2I建設者nginx的可用,如果你想要做的是舉辦一些靜態文件。

在最低看看它是如何做的事情。