NginxからJenkinsにProxyPass
インストール
参考:https://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkins+on+Ubuntu
$ wget -q -O - http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add - $ sudo sh -c 'echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list' $ sudo aptitude update $ sudo aptitude install jenkins
設定変更
$ sudo vi /etc/default/jenkins
ポート変更(任意)
40 # port for HTTP connector (default 8080; disable with -1) 41 HTTP_PORT=18080
URLを変更したいので、プレフィックスを付ける
参考:http://www.zzorn.net/2009/11/setting-up-hudson-on-port-80-on-debian.html)
59 JENKINS_ARGS="--webroot=/var/cache/jenkins/war --httpPort=$HTTP_PORT --ajp13Port=$AJP_PORT --prefix=/jenkins"
NginxからJenkinsにProxyPass
参考:https://wiki.jenkins-ci.org/display/JENKINS/Running+Hudson+behind+Nginx
1 server { 2 listen 80; # Listen on port 80 for IPv4 requests 3 4 server_name jenkins.example.com; 5 6 access_log /var/log/nginx/hudson_access.log; 7 error_log /var/log/nginx/hudson_error.log; 8 9 location ~ ^/static/[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]\/(.*)$ { 10 #rewrite all static files into requests to the root 11 #E.g /static/12345678/css/something.css will become /css/something.css 12 rewrite "^/static/[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]\/(.*)" /$1 last; 13 } 14 15 location /userContent { 16 #have nginx handle all the static requests to the userContent folder files 17 #note : This is the $JENKINS_HOME dir 18 root /var/lib/jenkins/; 19 if (!-f $request_filename){ 20 #this file does not exist, might be a directory or a /**view** url 21 rewrite (.*) /$1 last; 22 break; 23 } 24 sendfile on; 25 } 26 27 location @jenkins { 28 sendfile off; 29 proxy_pass http://127.0.0.1:8080; 30 proxy_redirect off; 31 32 proxy_set_header Host $host; 33 proxy_set_header X-Real-IP $remote_addr; 34 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 35 proxy_max_temp_file_size 0; 36 37 #this is the maximum upload size 38 client_max_body_size 10m; 39 client_body_buffer_size 128k; 40 41 proxy_connect_timeout 90; 42 proxy_send_timeout 90; 43 proxy_read_timeout 90; 44 45 proxy_buffer_size 4k; 46 proxy_buffers 4 32k; 47 proxy_busy_buffers_size 64k; 48 proxy_temp_file_write_size 64k; 49 } 50 51 location / { 52 #this is the jenkins web root directory (mentioned in the /etc/default/jenkins file) 53 root /var/run/jenkins/war/; 54 55 # Optional configuration to detect and redirect iPhones 56 if ($http_user_agent ~* '(iPhone|iPod)') { 57 rewrite ^/$ /view/iphone/ redirect; 58 } 59 60 try_files $uri @jenkins; 61 } 62 }
再起動
$ sudo /etc/init.d/jenkins restart * Restarting Jenkins Continuous Integration Server jenkins
確認
http://mydomain/jenkins