Nginx repo
CentOS:
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
RHEL:
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/rhel/$releasever/$basearch/
gpgcheck=0
enabled=1
manual installation
wget http://nginx.org/download/nginx-1.0.5.tar.gz
tar xvfz nginx-1.0.5.tar.gz
cd nginx-1.0.5
Install nginx
There are lot of options that you can pass to ./configure. To identify list of all the configuration options do the following.
./configure –help
./configure
make
make install
By default, Nginx will be installed in /usr/local/nginx. You may change this and other options with the compile-time options.
During ./configure, you might get the “./configure: error: the HTTP rewrite module requires the PCRE library.” error message about missing PCRE library that is required by nginx http rewrite module.
To solve the problem, either install “pcre” and “pcre-devel” packages on your Linux, or disable
the rewrite module by doing “./configure –without-http_rewrite_module”
/usr/local/nginx/conf/nginx.conf
ls /usr/local/nginx/logs/
access.log
error.log
nginx.pid
Side by Side
In some cases you may need to run both Apache (httpd) and Nginx on port 80. Such a situation can be a server running Cpanel/Whm and as such doesn’t support nginx, so you wouldn’t want to mess with the apache configuration at all.
To do this you have to make sure Apache and Nginx are bound to their own IP adddress, In the event of WHM/Cpanel based webserver, you can Release an IP to be used for Nginx in WHM. At this time I am not aware of a method of reserving an IP, and automatically forcing Apache to listen on a specific set of IPs in a control panel such as DirectAdmin or Plesk. But the link above will show you how with WHM/Cpanel.
Normally Apache will be listening on all interfaces, and such you may see a line like this in your httpd.conf file:
Port 80
#or
Listen 80
Instead you’ll need to tell apache to listen on a specific IP (you can have multiple Listen lines for multiple IPs)
Listen 192.170.2.1:80
Once you have apache configured to listen on a specific set of IPs you can do the same with nginx.
server {
listen 192.170.2.2:80;
...
}
Now that both servers are bound to specific IPs, both can then be started up on port 80. From there you would simply point the IP of the domain to the server you wish to use. In the case of WHM/Cpanel you can either manually configure the DNS entry for the domain going to nginx in WHM, or you can use your own DNS such as with your registrar to point the domain to the specific IP.
Apache behind Nginx
First thing that needs to be done is to change the interface apache listens on:
Listen 127.0.0.1:8080
So that Nginx can listen on port 80
Example of nginx configurations
server {
listen 80;
root /var/www/;
index index.php index.html index.htm;
server_name example.com;
location / {
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:8080;
}
location ~ /\.ht {
deny all;
}
}
No comments:
Post a Comment