Difference between revisions of "Nginx"
Line 49: | Line 49: | ||
<h2>Server block examples</h2> | <h2>Server block examples</h2> | ||
<h3>Two Server Blocks, Serving Static Files</h3> | <h3>Two Server Blocks, Serving Static Files</h3> | ||
+ | http { | ||
+ | index index.html; | ||
+ | |||
+ | server { | ||
+ | server_name www.domain1.com; | ||
+ | access_log logs/domain1.access.log main; | ||
+ | |||
+ | root /var/www/domain1.com/htdocs; | ||
+ | } | ||
+ | |||
+ | server { | ||
+ | server_name www.domain2.com; | ||
+ | access_log logs/domain2.access.log main; | ||
+ | |||
+ | root /var/www/domain2.com/htdocs; | ||
+ | } | ||
+ | } | ||
+ | |||
[[Category:Linux]] | [[Category:Linux]] |
Revision as of 09:35, 11 September 2013
Contents
How to install nginx on Centos.
Add nginx repo first. To add it, create the file /etc/yum.repos.d/nginx.repo with you favorite text editor, for example:
nano /etc/yum.repos.d/nginx.repo
Then insert the strings below and save the file:
[nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=0 enabled=1
Now you can install nginx with a simple command:
yum install nginx
To start nginx and allow it to start at boot:, type:
service nginx start chkconfig nginx on
If nginx doesn't start, make sure you haven't httpd service running and listening the same port (80). You can display running services with the command:
top
If you want to turn off httpd and disable it to start at boot, enter:
service httpd stop chkconfig httpd off
Main config file is /etc/nginx/nginx.conf. Also you can add hosts and discribe them in additional conf files /etc/nginx/conf.d/*.conf. You can base on example config file /etc/nginx/conf.d/default.conf
How to install nginx on Debian.
First append nginx repo to /etc/apt/sources.list
deb http://nginx.org/packages/debian/ squeeze nginx deb-src http://nginx.org/packages/debian/ squeeze nginx
Now install nginx
apt-get install nginx
Make sure you haven't apache2 service running and listening the same port (80). You can display running services with the command:
top
If you want to turn off apache2 and disable it to start at boot, enter:
service apache2 stop update-rc.d -f apache2 remove
Service nginx is set to start at boot by default. To start it manually, enter:
service nginx start
Main config file is /etc/nginx/nginx.conf. Also you can add hosts and discribe them in additional conf files /etc/nginx/conf.d/*.conf.
How to install nginx on Ubuntu.
First append nginx repo to /etc/apt/sources.list
deb http://nginx.org/packages/ubuntu/ lucid nginx deb-src http://nginx.org/packages/ubuntu/ lucid nginx
Now install nginx
apt-get install nginx
Make sure you haven't apache2 service running and listening the same port (80). You can display running services with the command:
top
If you want to turn off apache2 and disable it to start at boot, enter:
service apache2 stop update-rc.d -f apache2 remove
Service nginx is set to start at boot by default. To start it manually, enter:
service nginx start
Main config file is /etc/nginx/nginx.conf. Also you can add hosts and discribe them in additional conf files /etc/nginx/conf.d/*.conf.
Server block examples
Two Server Blocks, Serving Static Files
http { index index.html; server { server_name www.domain1.com; access_log logs/domain1.access.log main; root /var/www/domain1.com/htdocs; } server { server_name www.domain2.com; access_log logs/domain2.access.log main; root /var/www/domain2.com/htdocs; } }