Sunday 22 May 2011

How to Compile and Configure Nginx on OpenWrt


I have tested this guide on openwrt 10.03 (backfire) running on TPLINK TL-WR1043ND.

Install precompiled Nginx

If you don’t want to compile nginx by yourself, you can install nginx from openwrt web interface:

select System -> Software -> Update Package List -> Install Nginx


Compile Nginx

If you never build openwrt from source before, you must build it first. You can follow my other post : how-to-build-openwrt-from-source-for-tp-link-tl-wr1043nd/. Note, nginx is not on openwrt base package. So you must download additional package (feeds).



./scripts/feeds update -a
./scripts/feeds install -a
make menuconfig



On ‘make menuconfig’ select Network->nginx

Compiling nginx is very easy, thanks to openwrt developers!

 make menuconfig

choose Network->Nginx
make ./package/feeds/packages/nginx/compile

The nginx package will be placed at bin/[board_arch]/packages/nginx_0.7.67-3_ar71xx.ipk . In tplink tl wr1043nd : bin/ar71xx/packages/nginx_0.7.67-3_ar71xx.ipk


Configure Nginx

create nginx root directory



mkdir /www-nginx/default -p



Edit /etc/nginx/nginx.conf:


  • change the user from nobody to root

  • change nginx root directory to /www-nginx/default


this is the diff file



--- nginx.conf.ori Mon Mar 14 12:21:24 2011
+++ nginx.conf Tue Apr 6 08:53:37 2010
@@ -1,5 +1,5 @@
 
-#user nobody;
+user root;
worker_processes 1;
 
#error_log logs/error.log;
@@ -41,7 +41,7 @@
#access_log logs/host.access.log main;
 
location / {
- root html;
+ root /www-nginx/default;
index index.html index.htm;
}




Testing the configuration
create simple html file on /www-nginx/default/index.html.
Stop openwrt default web server and start nginx



/etc/init.d/uhttpd stop
/etc/init.d/nginx star





No comments:

Post a Comment