Nginx Web Server with PHP Support through Optware-NG

1 - Install Optware-NG from here

2 - Install nginx and php

ipkg install nano nginx php php-fcgi

3 - Backup default configuration file

mv /opt/etc/nginx/nginx.conf /opt/etc/nginx/nginx.conf-orig

4 - Create nginx configuration file, copy/paste in terminal:

cat >> /opt/etc/nginx/nginx.conf << 'EOF'
user nobody;
worker_processes 1;
events {
worker_connections 64;
}
http {
include mime.types;
default_type application/octet-stream;
server {
listen 82;
server_name localhost;
location / {
root /opt/share/nginx/html;
index index.html index.htm index.php;
}
error_page 500 502 503 504 /50x.html;
location = /opt/share/nginx/50x.html {
root html;
}
location ~ \.php$ {
root /opt/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}
EOF

Press Enter

5 - Create php-fcgi startup script

cat >> /opt/etc/init.d/S80php-fcgi << 'EOF'
#!/bin/sh
ENABLED=yes
PROCS=php-fcgi
ARGS="-b 127.0.0.1:9000"
PREARGS="/usr/bin/env PHP_FCGI_CHILDREN=2 PHP_FCGI_MAX_REQUESTS=1000"
DESC=$PROCS
PATH=/opt/sbin:/opt/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
. /opt/etc/init.d/rc.func
EOF

Press Enter

6 - Make script executable

chmod +x /opt/etc/init.d/S80php-fcgi

7 - Start server

/opt/etc/init.d/S80nginx start
/opt/etc/init.d/S80php-fcgi start

8 - Go to 192.168.1.1:82 and if you see this page, the nginx web server is configured correctly

 

9 - Create php info page:

cat >> /opt/share/nginx/html/info.php << 'EOF'
<?php
phpinfo();
?>
EOF

Press Enter

10 - Go to 192.168.1.1:82/info.php and if you see this page, php is configured correctly

ACCESS THE WEBSITE FROM WAN

nano /jffs/scripts/firewall-start

Paste this lines

#!/bin/sh
iptables -I INPUT -p tcp --destination-port 82 -j ACCEPT

Save with CTRL-O / Enter / and exit with CTRL-X
Make script executable and apply rule
chmod a+rx /jffs/scripts/firewall-start
sh /jffs/scripts/firewall-start

Go to Port Forwarding page http://192.168.1.1/Advanced_VirtualServer_Content.asp and redirect port 80 to 82, now you should have access from wan.


Enjoy...

Thanks @mercury for source

REVIEW (CLICK ON THE STARS TO RATE!)
4
Sending
User Review
4.86 (7 votes)