Hi, Guest!
+

How to install Nginx from source on Debian Linux

24-05-2013 linux nginx Roumen

Nginx

To install Nginx from source on Debian Linux, first you need to edit your apt sources:

/etc/apt/sources.list

and add the official nginx repo:

deb http://nginx.org/packages/debian/ squeeze nginx
deb-src http://nginx.org/packages/debian/ squeeze nginx

and add the PGP key:

wget -O key http://nginx.org/keys/nginx_signing.key && apt-key add key && rm -f key

Download latest source files:

apt-get source nginx

untar downloaded files and enter the folder:

tar -xvvf nginx-*.tar.gz && cd nginx-*

configure with right paths and desired modules:

./configure --conf-path=/etc/nginx/nginx.conf --sbin-path=/usr/local/sbin/nginx --error-log-path=/var/log/nginx.error --http-log-path=/var/log/nginx.access --with-http_realip_module --with-ipv6 --with-http_ssl_module --with-http_spdy_module

After compiling is done, just use:

make && make install

Now you are ready to start using nginx:

services nginx start

To see information about version paths and modules use:

nginx -V

To upgrade just repeat steps above with the new version of nginx, but before running "make install", make backup of your config files, because nginx.conf will be overwritten, also don't upgrade while nginx is running, first stop the service:

service nginx stop

Then delete some nginx files too:

rm -rf /usr/local/nginx && rm -f /usr/local/sbin/nginx

After all this you can install the new version.

  • Matthew S.
    This method work with nginx 1.4 too and you just need to add --with-http_spdy_module to use the new spdy module. Upgrading can be tricky, as you may need to delete /usr/local/sbin/nginx too before executing "make install".
  • Roumen
    Thank you for the feedback! You are right about deleting executable file first and the spdy module is a great idea.
  • Tosh0
    There is no need to delete anythink before update, just don't use custom sbin path and make symlink in /usr/sbin or /usr/local/sbin to /usr/local/nginx/sbin/nginx and when you install a new version old files will be overwritten. Also the installer won't overwrite nginx.conf on update, but making a backup is a good practice.
  • Bayu Permadi
    This metode work in 1.5.1 too but I install it from the source and just remember about "rm -f /usr/local/sbin/nginx". If you set your service manually or create your init script just remember where is your binary path.Kindly check with "which nginx", then it should be show where is your binary path. Change the "rm -f /usr/local/sbin/nginx" with "rm -f yourpath"