Site menu:

Simple guide to : Configuration of DVCS Mercurial Hg Server using Windows Server 2012 on IIS 8

Running Mercurial Hg (TortoiseHg) (DVCS) Server on Windows Server 2012 (IIS 8)

1. This document

This guide will help you to install and configure Mercurial Server (very popularly known as TortoiseHg server) under IIS8 on Windows Server 2012 (RC right now).

As we know Mercurial has built a light weight webserver known as hgserve which is bundled along with the TortoiseHg. But this simple webserver lacks few import aspects which follows:

• Access control, authentication and SSL which enables developers to securely push and pull code over the internet using a web based repository.

 

2. Prerequisites

We need following components readily available:

  1. Instance on Windows Server 2012 x64 (any of the editions which has Internet Information Services (IIS) 8 as a component)
  2. Microsoft Web Platform Installer 3.0 > URL Rewrite2.0
  3. Mercurial source as Python modules (Mercurial-2.2.2 (64-bit py2.6)) which can be downloaded from here (Mercurial-2.2.2 (64-bit py2.6) x64)
  4. Python 2.6 installer, which can be downloaded from (Python_2.6_Download x64)[Click here for complete list]
  5. Notepad++ 6.1.3 or latest (well you can use the default windows notepad if you like)
  6. TortoiseHg version 2.4.1-hg-2.2.2 –x64 from here or download the latest version which supports version hg-2.2.2, a complete list of TortoiseHg release can be found here
  7. hgweb.cgi file which can be downloaded from selenic download website and can be found as Mercurial 2.2.2 source release (direct Mercurial 2.2.2 source download link). If you feel finding this is a difficult job don’t worry, we will create one below during the installation process.
  8. index.cgi file to test the python 2.6 is working properly. We will create one below.
  9. You might want to download 7-Zip to extract the Mercurial Source tar zip file.
  10. Find all the configuration files in a rar (use 7-Zip to extract) file as attached for guys who are afraid of typing codes!

 

3. Easy steps to install Mercurial Hg server on IIS8

Just few easy steps to follow and we are ready.

3.1. Once Windows Server 2012 is ready to login, use administrator (preferable domain administrator) credentials to login to the operating system.

3.2. Configure Windows Server 2012 to soften the IE esc security, so that we can download all the prerequisite software(s).

3.3. Download all the prerequisite software(s) and files from their respected websites.

3.4. Open up Windows Server manager from application search screen.

3.5. You will find that a minimal installation of IIS 8 (Internet Information Services 8) already available with the OS.

3.6. From application manager click on Manage > “Add Roles and Features”

Windows Server manager: Add Roles and Features

Follow the wizard which appears

Windows Server manager: Add Roles and Features - 2

Windows Server manager: Add Roles and Features - 3

Windows Server manager: Add Roles and Features - 4

Windows Server manager: Add Roles and Features - 5

Windows Server manager: Add Roles and Features - 6

Remember to install all the options under Security and Application Development

Windows Server manager: Add Roles and Features - 7

Clicking next will show another list from which you should make sure you have .net framework 3.5 and 4.5 with Asp.Net selected

Windows Server manager: Add Roles and Features - 8

Click Install button and wait till this process is completed, the status will appear on the Action Center Flag or Server Manager Flag.

3.7. Now visit the Microsoft Web platform installer 3.0 website by following the url http://www.microsoft.com/web/downloads/platform.aspx and click on the Download button, when IE prompts click on run button. Search for URLRewrite 2.0 and install it.

Microsoft Web platform installer 3.0 website on IE 10

Microsoft Web platform installer 3.0 - URLRewrite 2.0

3.8. Install Python 2.6 in to its default directory “C:\Python26”

Showing installed path of Python 2.6 in Windows Server 2012

3.9. Install Mercurial source as Python modules (Mercurial-2.2.2 (64-bit py2.6))

3.10. Install TortoiseHg2.4.1-Hg-2.2.2-x64

3.11. Now launch IIS Manager and browse into “Default Web Site”, right click and click explore. Create a folder named Hg. Close the windows explorer and come back to “Default Web Site” right click and click refresh. You will find the folder named Hg under “Default Web Site”, now select the folder Hg, right click and make it as an application.

3.12. You will see that the yellow color folder has changed its icon into a small globe with some task-list on it. Now click the Hg Application and to the right double click on “Handler Mappings”

Internet Information Services (IIS) 8 Manager - Handler Mappings

You will see a list of predefined handlers

Internet Information Services (IIS) 8 Manager - Handler Mappings - Add Script Map - 1

Click on “Add Script Map..” from the Action tab over the right corner of the screen. A blank screen for adding script will appear.

Internet Information Services (IIS) 8 Manager - Handler Mappings - Add Script Map - 2

Now type:

Request path: *.cgi

Executable: c:\python26\python.exe -u "%s"

Name: Python

Internet Information Services (IIS) 8 Manager - Handler Mappings - Add Script Map - 3

Click OK.

Now if you scroll the handler mappings list you should see Python

Internet Information Services (IIS) 8 Manager - Handler Mappings - Add Script Map - 4

3.13. Now we need to test the correctness of Python Execution and so we will create a test file.

· Right click on hg application and click on explore.

· Create a notepad file and rename it to index.cgi and type the following texts

print 'Status: 200 OK'
print 'Content-Type: text/html'
print
print '<html><body><h1>Hello Administrator!</h1></body></html>'

 

creating index.cgi file in notepad++

Launch IE 10, and browse http://localhost/hg/index.cgi , you should see

Python is running on IIS 8 : Hello Administrator! on IE 10

3.14. Now open mercurial-2.2.2.tar.gz with 7-zip

opening mercurial-2.2.2.tar.gz with 7-zip

Browse inside till you find hgweb.cgi

extracting hgweb.cgi

Drag and drop or extract it to “C:\inetpub\wwwroot\hg\” and open it with notepad++

Now change

“config = "/path/to/repo/or/config"” it to “config = "/inetpub/wwwroot/hg/hgweb.config"”

Create a new textfile named as hgweb.config in to the same directory “C:\inetpub\wwwroot\hg\

And type the following:

[collections]
/Repositories/Hg = /Repositories/Hg
[web]
style = gitweb
allow_push = *
baseurl = /hg
push_ssl = true #or push_ssl=false (if we don’t have a SSL certificate)

 

Showing hgweb.config file in Notepad++

Each line has its individual meaning, which can be found explained below.

Note: I have used push_ssl = true as I will be using a self-signed certificate (and our production server has SSL from Startfield technologies) and use HTTPS protocol. And for people who do not wish to use https can have push_ssl = false set in the hgweb.config file

3.15. Now go to “C:” drive and create a directory named Respositories, and then go inside and create another directory named Hg. Now Create another directory named “TestRepo”. Browse into and right-click>TortoiseHg>Create Repository Here

TortoiseHg - Create Repository - 1

TortoiseHg - Create Repository - 2

Click on “Create” button

This will create a repository here.

3.16. Go back to IIS Manager, Click on “Default Web Site”> hg, to the right double click “URL Rewrite”

· Add a blank rule, Name it as hgweb.cgi,

· Match URl, Requested URL: “Matched the Pattern”

· Using: Wildcards

· Patterns: *, check the Ignore case

· Conditions, Logical grouping “Matched All”

· Click the Add.. button, and the condition input {REQUEST_FILENAME} and type as: Is Not a File

· Nothing on the Server Variables

· Action, Action type: Rewrite, Action properties: hgweb.cgi/{R:1} and check the first checkbox which says Append query string

Internet Information Services (IIS) 8 Manager - URL Rewrite

Click on “Apply” button to the action tab-panel.

3.17. Launch IE 10, and browse to http://localhost/hg/TestRepo/ you should see a the TestRepo hosted into IIS 8. Now open http://localhost/hg/ you will find the list of all the repo under this url.

3.18. Now to have domain basic authentication (remember this server should be inside a domain forest) just open IIS Manager, click on “Default Web Site”>hg application and double click on Authentication, Enable Basic Authentication and disable Anonymous Authentication.

3.19. Now when you launch http://localhost/hg you will see that IE asking for the username and password, type in the domain\username and password , you are inside. A point to remember, not all the domain users can push changes, to enable the users who can push changes should be given write and modify access under the security tab of the folder of the repository folder. In case of TestRepo, to give access to a user to push changes I should browse into C:\Repositories\Hg\ right-click on TestRepo directory, click on security tab add the specific user and give him/her the write and modification along with read.

Setting User rights

Setting User rights

Apply, and OK

If we need to restrict the read/pull of the repository to all, just edit the usernames with “Users” and Deny “Read 7 execute” and “Read” and uncheck allow modify, fullcontrol and write.

Setting User rights

Click Apply and OK.

3.20. Note: you might get some http issue when you are pushing large files greater than 2 MB per session, and this issue can be solved by adding

<httpRuntime executionTimeout="540000" maxRequestLength="2097151"/> 
Inside <system.web> and

<security><requestFiltering><requestLimits maxAllowedContentLength ="2147482624" /></requestFiltering></security>
Inside <system.webServer> In the web.config file

 

 

Configuring web.config to allow large files

3.21. Well that’s all Cool

4. Supporting Information

Well you guys can comment us here or contact us by filling the contact us form.

configuration files - hg.rar (2.66 kb)

Complete guide to install and configure Rhodecode on Ubuntu 12.04 using MySQL as the database instead of sqllite

 

Don’t like Mercurial Server’s interface? Or need more control try Rhodecode

 

This is a complete guide to install and configure Rhodecode on Ubuntu 12.04 using MySQL as the database instead of sqllite:

 Rhodecode is a awesome DVCS system which supports both Mercurial and Git and provides a better user interface and more functionality than hgweb.

 This guide is for people like me who are primary a windows people but want to install a neat DVCS on their server with basic working knowledge of Linux command prompt.

Alright enough said lets get down with business

 Step 1: Install Ubuntu 12.04 LTS ( 64 bit) on your server or VM

 Make sure the network is working,try

ini@ubuntu:~$ ifconfig

 To start with it should show something meaningful for you in front of eth0 see example below

 

eth0Link encap:EthernetHWaddr 08:00:27:31:80:6b
inet addr:10.10.1.202Bcast:10.255.255.255Mask:255.0.0.0
inet6 addr: fe80::a00:27ff:fe31:806b/64 Scope:Link
UP BROADCAST RUNNING MULTICASTMTU:1500Metric:1
RX packets:2816 errors:0 dropped:0 overruns:0 frame:0
TX packets:891 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:653933 (653.9 KB)TX bytes:329047 (329.0 KB)
loLink encap:Local Loopback
inet addr:127.0.0.1Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNINGMTU:16436Metric:1
RX packets:357 errors:0 dropped:0 overruns:0 frame:0
TX packets:357 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:25587 (25.5 KB)TX bytes:25587 (25.5 KB)

 

If not you need to setup your network, if you know how to do that on Ubuntu 12.04 then its great if not try this quick tutorial

I assume your network is working just fine and you are able to ping to the internet from your console.

 Step 2: Grant yourself root access (though extremely dangerous due to the fact that there is no undo in linux by default, I prefer this as it is simply a PITA to type sudo everytime. I got rmed not a great experience anyways to use the system as root!! lol )

ini@ubuntu:~$ sudo su
[sudo] password for ini: enter your user password here

  The prompt will change to something like this

root@ubuntu:~$

 Step 3: is to Update/ upgrade your installation

 Now we will make sure the Ubuntu installation is up to date

root@ubuntu:~$apt-get update
root@ubuntu:~$apt-get upgrade

Your Ubuntu installation will now search and download updates, wait for some time till both the commands complete.

 Now let us install pip

root@ubuntu:~$ apt-get install python-pip

  Now we are ready to install virtualenv, this creates a virtual environment for python so that if you run multiple instances with different versions, there will be no clash of versions between them. Using pip

root@ubuntu:~$ pip install virtualenv

  Also install MySql (we want mysql in place for the database Rhodecode uses)

root@ubuntu:~$ apt-get install mysql-server

  The following installs the python wrapper for mysql server, you need this to ensure you do not get MySQLdb not found

root@ubuntu:~$ apt-get install python-mysqldb

  Some more dependencies ( maybe iam doing an overkill but does it matter ?)

root@ubuntu:~$ apt-get install libmysqlclient-dev

 

Step 4: Now we instgall RabbitMQ server

root@ubuntu:~$ apt-get install rabbitmq-server

  Create a rabbit user

root@ubuntu:~$ rabbitmqctl add_user rhodeuser rhodepass

 Add a vhost to RabbitMQ

root@ubuntu:~$ rabbitmqctl add_vhost rhodevhost

Step 5: let us installpython dev package

root@ubuntu:~$ apt-get install python-dev

 Now we need to create the directory where everything belonging to Rhodecode will be installed, I name it rhode, you can make your choice

root@ubuntu:~$ cd /
root@ubuntu:/# mkdir /rhode

You are the root, but then again just to make sure I give temp ownership of the folder to my username (here ini is my username)

root@ubuntu:/# chown ini /rhode

 now we need to make the directory structure inside , and install rhodecode, this is a bit different from windows install which I will post a tutorial as well, first setting up venv at /rhode/venv

root@ubuntu:/# virtualenv --no-site-packages /rhode/venv

 you can also do

root@ubuntu:/# virtualenv /rhode/venv

  now that you have created the venv lets activate it

 browse to /rhode/venv/bin

root@ubuntu:/# cd /rhode/venv/bin
root@ubuntu:/rhode/venv/bin# source activate


 Now you are in virtual env for rhodecode , the prompt should show something like this

(venv)root@ubuntu:/rhode/venv/bin#

 Now go back to the root dir by doing

(venv)root@ubuntu:/rhode/venv/bin# Cd /

  And install pastescript using pip

(venv)root@ubuntu:/# pip install pastescript

  Then install rhodecode using

(venv)root@ubuntu:/# pip install rhodecode

  This will take a lot of time for slow connections, be patient while it completes installation

 The installation will show a lot of warnings, I ignored them all ( there were a lot of them and scrolling too fast to make anything out of them) another reason why I don’t really prefer linux for production use( though I like it’s speed and performance)

 Step 6: Once this is done go to /rhode/data and execute the paster to make production.ini file

 While in venv

(venv)root@ubuntu:/# cd /rhode/data/

  And then

(venv)root@ubuntu:/rhode/data# paster make-config RhodeCode production.ini

 

Step 7: Make a mysql db before we go any further as we plan to use mysql for the database instead of the default sqllite, this is better for production use and a lot more reliable.

 Let us create the mysql database and users, grant them permission

 So type in

root@ubuntu:/# mysql –p root –u
 
mysql> create database rhodecode character set utf8; 
mysql> create user 'rhodecode'@'localhost' identified by 'my_password';
mysql>grant all privileges on rhodecode.* to 'rhodecode'@'localhost';
mysql>flush privileges; mysql>exit

  Go back to venv if you are not in venv already or exited it due to some reason. Type in console:

root@ubuntu:/# /rhode/venv/bin/source activate
(venv)root@ubuntu:/#

 

Step 8: Now that you are in venv, let us find out the package called MySQLdb, this is actually the python wrapper for MySQL (though we installed it earlier through pip, it still showed me errors making paster run configure on production.ini

 That’s why we take the harder way and build it again, this will add python into the system path, twice once for venv, once system wide, if it shows any warnings relating to double entry of path, ignore and go ahead with it as I did. Experienced linux guys would know better how to do it.

So now get the wrapper from its website, extract it and then install it.

(venv)root@ubuntu:/# wget http://ncu.dl.sourceforge.net/project/mysql-python/mysql-python/1.2.3/MySQL-python-1.2.3.tar.gz
(venv)root@ubuntu:/# tar –zxvf MySQL-python-1.2.3.tar.gz
(venv)root@ubuntu:/# cd MySQL-python-1.2.3
(venv)root@ubuntu:/MySQL-python-1.2.3# python setup.py build

  The build should complete without errors

 Now we install

(venv)root@ubuntu:/ MySQL-python-1.2.3# python setup.py install

  Remember to be as the root all the time else it may fail.

 Step 9: Now we are good to set up the production.ini file genertated by the paste script earlier.

 So lets go to /rhode/data/

(venv)root@ubuntu:/ MySQL-python-1.2.3# Cd /rhode/data

  now on to editing the production.ini

 I use nano and completely hate vim or its clones or whatever ( sorry, its just because you have to spend rest of your live learning to use a text editor rather than getting things done)

 I issue the following command while in the data directory as before

(venv)root@ubuntu:/rhode/data#nano production.ini

  In there look for the following and make changes, this is crucial, so be careful, double check just in case, leave the host to 127.0.0.1 - ( thanks for the correction Marcin)

[server:main]

host = 127.0.0.1

 you can also change the port= 5000 anything you please other than 80 and 443 , I dint do it.

 Next, in the same file find CELERY CONFIG section in the same file. There change

use_celery = false

 To

use_celery = true

 Remove the line which looks like

Broker.host = localhost

 Please don’t comment it out, in my experience sometimes commented sections are also read ( gitorious installation blues!) So I prefer to remove them, anyways its your choice, you have been warned.

Change broker.vhost = rabbitmqhost

  to

broker.vhost = rhodevhost

Remember we added a vhost while setting up celery. Leave the broker.port as it is (unless you have done something earlier). Also change the subsequent directives to the following:

Broker.user = rhodeuser
Broker.password = rhodepass

Now go to the DB CONFIGS section in the same file and remove SQLLITE section and POSTGRESQL section.

Change sqlalchemy.db1.url = mysql://username:password@localhost/rhodecode

  To

sqlalchemy.db1.url = mysql://rhodecode: my_password@localhost/rhodecode

Remember the database, user and password we created at the beginning of this tutorial, use them here.

This is pretty much what you want to do, you can play around other configs if you want but I haven’t tried them much, if anyone tries other configs please let me know your experiences as well.

Step 10: Now we are good to make rhodecode serve us fantastic hg and git

Generate the Rhodecode database using the following command (this is required every time you change the production.ini,and destroys the previous db, so use this with care, and avoid changing configs while in production, but anyways, your repos are always safe, don’t worry even if you want to change config again and again if you are the only user or only few people use it.

 While in venv,

Grant the permissions to rhodeuser and rhodehost to make celeryd connect to rabbitmq

 

rabbitmqctl set_permissions -p rhodevhost rhodeuser ".*" ".*" ".*"

Run the paster setup

(venv)root@ubuntu:/ rhode/data# paster setup-rhodecode production.ini

  This will now run (hopefully without any errors and ask you questions on admin username, password and location to store repositories which we made earlier which was: /rhode/repo/

Start celery using configuration from production .ini with the following command

(venv) paster celeryd production.ini &

  Hit enter and then type the following command

(venv) paster serve production.ini

 Fire up your browser if u have gui on Ubuntu and go to http://127.0.0.1:5000 or if on VM, go to http://your-vm-ip:5000

 If everything is okay, you got Rhodecode up and running. Now that’s not enough, is it?

 Step 11: On a production environment, you need a proper web server to proxy it, maybe have ssl as well.

 If you want you can proxy this on apache2 or on nginx. Before we do anything further, you want to start rhodecode automatically when Ubuntu starts as a service or as a daemon (as they call it in Linux world to do that we need to create a user who can start it automatically.

 Type in as root not in venv

 

adduser --no-create-home \ 
            --disabled-login \ 
            --system –group rhodecode

  Give the new user rhodecode the ownership of /rhode directory

chown rhodecode:rhodecode-R /rhode

 (this dint really work for me and I always started Rhodecode as root, if someone knows a not too difficult way to use this as user: rhodecode, please post them on the comments, I will be glad to use that)

Step 12: Now we need to create the init.d script to start rhodecode as daemon.

 In the Rhodecode source, they guys have included neat daemon scripts for the major linux distros, since we are using Ubuntu, which is a debian distro, we select the file called rhodecode-daemon2Here as a matter of fact don’t use any older scripts but the latest one from the sourcecode itself otherwise you will spend the rest of the day debugging the script ( it happened to me but then hey Iam a not a linux geek and all I wanted is to get this work)

 You can download it from bitbucket repo of rhodecode by

wget https://bitbucket.org/marcinkuzminski/rhodecode/raw/51b203e44202/init.d/rhodecode-daemon2

 Now the tricky part, edit this file

(venv)root@ubuntu:/# nano rhodecode-daemon2

  lookup the following lines

 

APP_NAME="rhodecode"
APP_HOMEDIR="marcink/python_workspace"
APP_PATH="/home/$APP_HOMEDIR/$APP_NAME"
CONF_NAME="production.ini"
PID_PATH="$APP_PATH/$APP_NAME.pid"
LOG_PATH="$APP_PATH/$APP_NAME.log"
PYTHON_PATH="/home/$APP_HOMEDIR/v-env"
RUN_AS="marcink"

 Change them as

APP_NAME="rhodecode"
APP_HOMEDIR="/rhode"
APP_PATH="/rhode/data"
CONF_NAME="production.ini"
PID_PATH="$APP_PATH/$APP_NAME.pid"
LOG_PATH="$APP_PATH/$APP_NAME.log"
PYTHON_PATH="/$APP_HOMEDIR/venv/bin"
RUN_AS="root" # this is not advisable but you can put in your username if #it works for you

 Save the file and make it executable

(venv)root@ubuntu:/# chmod +x rhodecode-daemon2

  Try running it

(venv)root@ubuntu:/# ./ rhodecode-daemon2 start

  If it starts, check up rhodecode in your browser. I hope everything should be fine then stop it

(venv)root@ubuntu:/# ./ rhodecode-daemon2 stop

  Now copy this script into the /etc/init.d/ directory and change its name to rhodecode ( I change the name since everything I use in this is either rhodecode and rhodepass)

(venv)root@ubuntu:/# cp ./rhodecode-daemon2 /etc/init.d/rhodecode

  go into /etc/init.d

(venv)root@ubuntu:/# cd /etc/init.d/

  Update the init scripts with rhodecode

(venv)root@ubuntu:/etc/init.d/# update-rc.d rhodecode defaults

  just in case you want, you can try out the following command anywhere in the system

(venv)root@ubuntu:/# service rhodecode start

  and

(venv)root@ubuntu:/# service rhodecode stop

 

Step 13: Great now everything till now is cool.

 Some admins want LDAP support ( so that there is no more manual account creation and deletion of users and rights in Rhodecode)

 We can install LDAP support by simply running the following command and then configuring it from the Rhodecode admin section inside the application ( that’s from the browser)

 Coming back to nginx setup, lets get some prerequisites for nginx

root@ubuntu:/# apt-get install libpcre3-dev build-essential

 If this fails (mine failed, try)

root@ubuntu:/# apt-get install libpcre3-dev build-essential --fix-missing

  lets create the user for nginx service

root@ubuntu:/# adduser --no-create-home \

                                    --disabled-login \

                                    --disabled-password \

                                    --system --group nginx

  Now get the latest nginx from it’s website

root@ubuntu:/# wget http://nginx.org/download/nginx-1.3.1.tar.gz

 Once downloaded extract it

root@ubuntu:/# tar –zxvf nginx-1.3.1.tar.gz

 get inside the nginx directory

root@ubuntu:/# cd nginx-1.3.1

 Configure the installer to setup with http and ssl modules (for https access)

root@ubuntu:/nginx-1.3.1# ./configure --prefix=/opt/nginx --with-http_ssl_module

 Once successful, lets compile it by issuing make command

root@ubuntu:/nginx-1.3.1# make

 Once done do an install

root@ubuntu:/nginx-1.3.1# make install

 (Remember to be the root user all the way to avoid the sudo pain and other random errors!)

 Once installed create SSL keys, please enter the following one by one in your console as root

root@ubuntu:/nginx-1.3.1# cd /opt/nginx/conf
root@ubuntu:/opt/nginx/conf# openssl genrsa -des3 -out server.key 1024
root@ubuntu:/opt/nginx/conf# openssl req -new -key server.key -out server.csr
root@ubuntu:/opt/nginx/conf# cp server.key server.key.orig
root@ubuntu:/opt/nginx/conf# openssl rsa -in server.key.orig -out server.key
root@ubuntu:/opt/nginx/conf# openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
root@ubuntu:/opt/nginx/conf# rm server.csr
root@ubuntu:/opt/nginx/conf# chmod 600 server.crt server.key

 

Answer the questions the script pops up, this will make the security certificate for you to use once done remove the stock nginx.conf from :/opt/nginx/conf directory, well unless you know how to modify it to suit the purpose here, I removed and replaced it with the one below

root@ubuntu:/opt/nginx/conf# rm nginx.conf

 Download this script from https://raw.github.com/gist/2866413/9103512672ac91c335edf642499f0a37decaba9e/nginx.conf

wget https://raw.github.com/gist/2866413/9103512672ac91c335edf642499f0a37decaba9e/nginx.conf

 Once downloaded, fire up nano

root@ubuntu:/opt/nginx/conf# nano nginx.conf

 And check if it is the correct file ( just incase!)

 And download this config file

Wget https://raw.github.com/gist/2866413/5994c995631e49a22a9503864d2b1f855f9539ef/rhodecode.conf

 Or else you can fire up nano and create this file with the following lines

root@ubuntu:/opt/nginx/conf# Nano rhodecode.conf

 

proxy_redirect off;
proxy_set_headerHost $host;
proxy_set_headerX-Url-Scheme $scheme;
proxy_set_headerX-Host $http_host;
proxy_set_headerX-Real-IP $remote_addr;
proxy_set_headerX-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_headerProxy-host $proxy_host;
client_max_body_size 400m;
client_body_buffer_size 128k;
proxy_bufferingoff;
proxy_connect_timeout 7200;
proxy_send_timeout 7200;
proxy_read_timeout 7200;
proxy_buffers8 32k;


 Now we are good to test nginx, and if it is passing rhodecode to ssl

 First start the Rhodecode service (else you will see bad gateway error from nginx)

 As root:

root@ubuntu:/# service rhodecode start
 start nginx
root@ubuntu:/# /opt/nginx/sbin/nginx
Open up your browser and go to https://your-vm-ip/
You should see Rhodecode instance running, now stop the service with the following command
root@ubuntu:/# /opt/nginx/sbin/nginx -s stop
Or 
root@ubuntu:/# /opt/nginx/sbin/nginx stop
 Then stop rhodecode service
root@ubuntu:/# sudo service rhodecode stop

 Now it is clear that nginx works as intended ( the http wont work as we dint configure it)

 

Step 14: Install nginx as a daemon, download nginx-init.d.sh from https://raw.github.com/gist/2866413/a62cc8ba4d86e06c138d9fc27b580ff2759e3bfe/nginx-init.d.sh

root@ubuntu:/# wget https://raw.github.com/gist/2866413/a62cc8ba4d86e06c138d9fc27b580ff2759e3bfe/nginx-init.d.sh

 No need to edit it as it works just fine for but just in case check for the PREFIX=/opt/nginx

 Now we can install the script so that it starts at boot.

 

root@ubuntu:/# sudo cp ./nginx-init.d.sh /etc/init.d/nginx
root@ubuntu:/# cd /etc/init.d
root@ubuntu:/etc/init.d# sudo update-rc.d nginx defaults

 

You may want to test the script again by running

root@ubuntu:/etc/init.d# service nginx start

 Note this time since rhodecode is not running, you will get a bad gateway error when you navigate to https://your-vm-ip

 stop the nginx service

root@ubuntu:/etc/init.d# service nginx stop

 Go for a reboot and once at login prompt ( no need to login), fireup firefox and check on https://your-vm-ip if Rhodecode is working fine

 Congratulations, you have a working DVCS repo  with all production grade functionalities ( you however may need to setup a firewall to block http://your-ip:5000 from being directly accessible, at Excedalogic we use it on hyper-v and the host system using Windows Server 2008 R2has a firewall configured for that purpose ( it does the job very well)

UPDATE: Marcin Kuzminski suggested changes to the earlier setup in step 9 instead of changing the host = 127.0.0.1 to 0.0.0.0, let it remain at 127.0.0.1, this way Rhodecode will only be accessable to the machine running it and no need to setup a firewall.

 

 

 Phew.. that wasn’t too hard however I could not have written this without the great guide at https://gist.github.com/2866413 , another one about the MYSQLdb errors at http://crucial-systems.com/installing-mysqldb-ubuntu-mysql-python

 I will upload a VM as well (VBOX VHD) or put up a torrent if anyone wants it.

 Thanks for your time, please contribute to the discussion here and share this tutorial.

 Suggestions, feedbacks are always welcome to refine this guide and share your experiences with Rhodecode.

Ini karan, CEO Excedalogic IT Services India Private Limited

www.excedalogic.com