一、nginx基础配置
1.nginx模块
官方模块文档使用帮助:点击
1.1 nginx core modules(必须的)
包括
main
events
2. standard http modules (默认安装)
core
access
fastcgi
gzip 压缩模块
log 日志模块
proxy
rewrite URL 重写模块
upstream 负载均衡模块
2.配置文件解释
[root@nginx nginx]
1 worker_processes 1 ;
2 events {
3 worker_connections 1024 ;
4 }
5 http {
6 include mime.types;
7 default_type application/octet-stream;
8 sendfile on;
9 keepalive_timeout 65 ;
10 server {
11 listen 80 ;
12 server_name localhost;
13 location / {
14 root html;
15 index index .html index .htm;
16 }
17 error_page 500 502 503 504 /50 x .html;
18 location = /50x.html {
19 root html;
20 }
21 }
22 }
二、配置三个虚拟主机
1.编写配置文件
[root@nginx nginx]
[root@nginx nginx]
1 worker_processes 1 ;
2 events {
3 worker_connections 1024 ;
4 }
5 http {
6 include mime.types;
7 default_type application/octet-stream;
8 sendfile on;
9 keepalive_timeout 65 ;
10 server {
11 listen 80 ;
12 server_name www.liang.com;
13 location / {
14 root html/www;
15 index index .html index .htm;
16 }
17 }
18 server {
19 listen 80 ;
20 server_name bbs.liang.com;
21 location / {
22 root html/bbs;
23 index index .html index .htm;
24 }
25 }
26 server {
27 listen 80 ;
28 server_name blog.liang.com;
29 location / {
30 root html/blog;
31 index index .html index .htm;
32 }
33 }
34 }
[root@nginx nginx]
[root@nginx nginx]
2.检查语法
[root@nginx nginx]
nginx: the configuration file /usr/local /nginx-1.6 .2 /conf/nginx.conf syntax is ok
nginx: configuration file /usr/local /nginx-1.6 .2 /conf/nginx.conf test is successful
3.重启
[root@nginx nginx]
4.打开另一台虚拟机测试
[root@lamp ~]# tail -1 /etc/hosts
10.0 .0 .129 www.liang .com bbs.liang .com blog.liang .com
[root@lamp ~]# curl www.liang.com
www.liang .com
[root@lamp ~]# curl bbs.liang.com
bbs.liang .com
[root@lamp ~]# curl blog.liang.com
blog.liang .com