2017-02-12 2 views
1

我有Jenkins在IP上運行的CentOS 7虛擬機上運行,​​說的是129.215.193.34。所以,我可以使用129.215.193.34:8080訪問Jenkins。我想使用nginx,因此用戶不必輸入:8080,只需輸入IP號碼即可。 nginx的安裝和插入後在/etc/nginx/nginx.conf配置nginx指向Jenkins服務器時出錯

location/{ 
    proxy_pass http://127.0.0.1:8080; 
    proxy_redirect off; 
    proxy_set_header Host $host; 
    proxy_set_header X-Real-IP $remote_addr; 
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
    proxy_set_header X-Forwarded-Proto $scheme; 
} 

以下,但訪問到129.215.193.34當我得到一個一般性錯誤。我怎麼知道這裏有什麼問題?我可以看到129.215.193.34:8080詹金斯網絡接口,但沒有對剛剛129.215.193.34

nginx.conf的其餘部分看起來像這樣

user nginx; 
worker_processes auto; 
error_log /var/log/nginx/error.log; 
pid /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; 

    server { 
     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/{ 
      sendfile off; 
      proxy_pass   http://127.0.0.1:8080; 
      proxy_redirect  default; 

      proxy_redirect off; 
      proxy_set_header Host $host; 
      proxy_set_header X-Real-IP $remote_addr; 
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
      proxy_set_header X-Forwarded-Proto $scheme; 
     } 

    error_page 404 /404.html; 
     location = /40x.html { 
    } 

    error_page 500 502 503 504 /50x.html; 
     location = /50x.html { 
    } 
} 
+0

你有服務器部分嗎?你可以把整個nginx配置在這裏嗎? – Rik

+0

@Rik好的,對不起。讓我更新它。 – Manolete

+0

嘗試更改只偵聽外部IP的「服務器」部分。 '聽129.215.193.34:80 deafult_server'並重新啓動nginx。在位置有一個重複的'proxy_redirect',但你需要使它工作的是'proxy_pass'。所以你可能想先嚐試一下。 – Rik

回答

1

您可以驗證,如果nginx的配置是否正確運行(作爲root)

nginx -t 

如果這是正確的,檢查代理的工作原理(你應該在nginx配置中找到一些東西)。運行

tail -f /var/log/nginx/error.log 

和捲曲的機器

curl -I http://<ip>:80/ 

在SELinux的,allow daemons to connect to the service

setsebool -P httpd_can_network_connect on 
主機上