之前同事架了個 Redmine,現在他被調去其他 team 協助。剛好最近在架設 Apache reverse proxy,按照上級的意思,希望 Redmine 能夠在 proxy server 的 domain 之下,例如 http://web.platform.team/redmine

登入到 Redmine server 後,發現他是用 passenger 啟動 daemon,listen 3000 port。而 80 port 被 nginx 給佔用了。經過多次的實驗,不知道為甚麼,我設定 proxypass 無法將 http://web.platform.team/redmine 導向 http://redmine.platform.team:3000/

我猜是 port number 的問題,可是在網路上看到別人似乎是可以 :'(
因此最後決定,想辦法讓 nginx 來提供 redmine

gooooooooogle 一番後,找了一篇教學文章: HowTo configure Nginx to run Redmine

解決方法

Configure Redmie server

步驟如下:

  1. 安裝 nginx , thin

    apt-get install nginx thin
    
  2. 產生 thin 的設定檔

    /etc/thin/redmine.yml
    ---
    pid: tmp/pids/thin.pid
    group: redmine
    wait: 30
    timeout: 30
    log: log/thin.log
    max_conns: 1024
    require: []
    
    environment: production max_persistent_conns: 512 servers: 4 daemonize: true user: redmine socket: /tmp/thin.sock chdir: /opt/redmine prefix: /redmine
  3. 修改 Nginx 設定

    /etc/nginx/site-enabled/default
    upstream thin_cluster {
        server unix:/tmp/thin.0.sock;
        server unix:/tmp/thin.1.sock;
        server unix:/tmp/thin.2.sock;
        server unix:/tmp/thin.3.sock;
    }
    
    server {     listen 80;     server_name redmine.platform.team;
        access_log /var/log/nginx/redmine_access.log;     error_log /var/log/nginx/redmine_error.log;
        proxy_redirect off;     proxy_set_header Host $http_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;     client_max_body_size 10m;     client_body_buffer_size 128k;     proxy_connect_timeout 90;     proxy_buffer_size 4k;     proxy_buffers 4 32k;     proxy_busy_buffers_size 64k;     proxy_temp_file_write_size 64k;
        root /opt/redmine/public;
        location / {         try_files $uri/index.html $uri.html $uri @cluster;     }
        location @cluster {         proxy_pass http://thin_cluster;     }
        # redirect server error pages to the static page /50x.html     #     error_page 404 /404.html;     error_page 500 502 503 504 /50x.html;     location = /50x.html {         root /usr/share/nginx/html;     }     # deny access to .htaccess files, if Apache's document root     # concurs with nginx's one     #     location ~ /\.ht {         deny all;     } }
  4. 啟動 service

    service thin start
    service nginx restart
    

到這裡,Redmine server 的部分就設定完成,雖然不是這麼的完美。如果網址只打 http://redmine.platform.team/ ,會出現一行訊息: Not Found: /
但是如果網址加上 /redmine,也就是 http://redmine.platform.team/redmine ,這樣就能看到完整的 Redmine 頁面


前面提到,我還需要設定 Apache reverse proxy ,因此也順便作個紀錄。

在 Apache virtual host configuration 上新增 proxypass 語法:

ProxyPass /redmine http://redmine.platform.team/redmine
ProxyPassReverse /redmine http://redmine.platform.team/redmine

將 Apache reverse proxy 的網址 (例如: http://www.platform.team/redmine 導向 http://redmine.platform.team/redmine)

不過只有這樣的話,Redmine 還是不能用,需要將一些額外的 prefix 一併轉過去

ProxyPass /stylesheets http://redmine.platform.team/stylesheets
ProxyPassReverse /stylesheets http://redmine.platform.team/stylesheets
ProxyPass /javascripts http://redmine.platform.team/javascripts
ProxyPassReverse /javascripts http://redmine.platform.team/javascripts
ProxyPass /images http://redmine.platform.team/images
ProxyPassReverse /images http://redmine.platform.team/images

完工囉

PS: 這篇格式也太難調整了,第一次覺得 markdown 這麼難用= =

Comments

comments powered by Disqus