All for Joomla All for Webmasters

Nginx Installation and Configuration


Nginx quickly delivers static content with efficient use of system resources. It can deploy dynamic HTTP content on a network using FastCGI handlers for scripts, and can serve as a very capable software load balancer. Nginx uses an asynchronous event-driven approach to handling requests which provides more predictable performance under load, in contrast to the Apache HTTP server model that uses a threaded or process-oriented approach to handling requests.Install required packages,

# yum install -y httpd*

#wget ftp://ftp.pbone.net/mirror/centos.karan.org/el5/extras/testing/i386/RPMS/nginx-0.6.39-1.el5.kb.i386.rpm

# rpm -ivh nginx-0.6.39-1.el5.kb.i386.rpm

or

# yum install nginx -y

Setting up nginx as a reverse proxy:

# vim /etc/nginx/nginx.conf

Change worker_processes 1 To worker_processes 2.

Replace
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main ‘$remote_addr – $remote_user [$time_local] $request ‘
‘”$status” $body_bytes_sent “$http_referer” ‘
‘”$http_user_agent” “$http_x_forwarded_for”‘;
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
# Load config files from the /etc/nginx/conf.d directory
include /etc/nginx/conf.d/*.conf;
#
# The default server
#

server {
listen 80;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}To

http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main ‘$remote_addr – $remote_user [$time_local] $request ‘
‘”$status” $body_bytes_sent “$http_referer” ‘
‘”$http_user_agent” “$http_x_forwarded_for”‘;
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
gzip on;
# Load config files from the /etc/nginx/conf.d directory
include /etc/nginx/conf.d/*.conf;
#
# The default server
#
server {
listen 80;
server_name YOURSERVERNAME;
#charset koi8-r;
#access_log logs/host.access.log main;
#Main location
location / {

proxy_pass http://127.0.0.1:8080/;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
root /usr/share/nginx/html;
index index.html index.htm index.php;
}This function allows nginx to work with these file types:

Change

#location ~ /\.ht {
#deny all;

To

location ~*
^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|wav|bmp|rtf|js)$ {root /var/www;}

Test nginx configuration file by,

# nginx -t

The result must be like this:

2010/12/02 12:09:40 [info] 1257#0: the configuration file /etc/nginx/nginx.conf syntax is ok

2010/12/02 12:09:40 [info] 1257#0: the configuration file /etc/nginx/nginx.conf was tested successfully

Install rpaf-2.0 module which gives active Nginx IPs to Apache.

# cd /tmp

# wget http://stderr.net/apache/rpaf/download/mod_rpaf-0.6.tar.gz

# tar xzf mod_rpaf-0.6.tar.gz

# cd mod_rpaf-0.6

# vim makefile

Change APXS=$(shell which apxs) to APXS=/usr/sbin/apxs.

Save and exit the file.

# make rpaf-2.0 && make install-2.0

Edit apache configuration file,

# vim /etc/httpd/conf/httpd.conf

add below lines to it.

….
LoadModule rpaf_module modules/mod_rpaf-2.0.so
….
#Mod_rpaf settings
RPAFenable On
RPAFproxy_ips 127.0.0.1 REALIP1 REALIP2
RPAFsethostname On

Note: Change Listen 80 to Listen 8080, because nginx will use port 80.

Save and exit the file.

# service httpd restart
# service nginx start


Like it? Share with your friends!

1 SHARES
0
1 SHARES, 0 points

Nginx Installation and Configuration

log in

Become a part of our community!

reset password

Back to
log in
Choose A Format
Personality quiz
Trivia quiz
Poll
Story
List
Meme
Video
Audio
Image