linux nginx 指向conf,nginx.conf 示例配置

1、nginx.conf配置文件:

[root@node5 nginx]# grep -v "#" nginx.conf

user  nginx;    #运行nginx的用户身份

worker_processes  8;  #nginx启动的核心数,一般比物理CPU核心少一个,并且可以做绑定

events {

use epoll;    #定义使用的事件模型

worker_connections  4096;  #每个nginx工作进程的最大连接数

}

http {

include       mime.types;

default_type  application/octet-stream;

sendfile on;

tcp_nopush on;

tcp_nodelay on;

server_tokens off;

keepalive_timeout 65;

server_names_hash_max_size 1024;

gzip on;

gzip_proxied any;

gzip_min_length 1000;

gzip_comp_level 4;

gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

gzip_static on;

server {   #定义一个server,相当于apace的虚拟主机

listen       80;  #定义改虚拟主机监听的端口

server_name  node5.a.com;   #虚拟机的主机名

location / {

root   html/www;   #定义用户访问node5.a.com/的时候,针对的服务器上的index.html或index.php,本次放在/opt/nginx/html,里面有个index.htmk默认首页。

index  index.php  index.html index.htm;  #定义支持的页面文件类型

}

}

include  html/*.conf;     #这个是重点,相当于加载html/任何以.conf结尾的文件,可以方便定义虚拟主机为名称的配置文件,这样可以简化配置,且方便管理多个虚拟主机文件,而html具体路径是 /opt/nginx/html。

}

2、/opt/nginx/html:里面有三个文件和一个目录如下:

1).50x.html:nginx自定义的服务器内部错误首页:

2)index.html:在nginx.conf定义的node5.a.com的访问路径文件

3)node5.a.org.conf:在nginx.conf配置文件定义引用的.conf文件,这样为每个虚拟机主机都创建一个配置文件,更加模块化,期内容如下:

server {

listen 80;

server_name node5.a.org;

location /  {

root  /www/b.org;   #定义node.a.org在服务器的访问文件路径:

index index.php  index.html index.htm;

#        include  html/*.conf;

location /Download/ {   #自定义一个站点,即访问node5.a.org/Download的路径。

root /www/b.org; #定义访问node5.a.org/Download其实是访问的服务器的/www/b.org/Download。

autoindex on;

}

}

}

~

4)www:是nginx.conf定义的node5.a.com的文件爱你所在目录

3.为node5.a.org创建/www目录和/www下的Download目录及index.html首页

[root@node5 b.org]# pwd

/www/b.org

[root@node5 b.org]# ls

Download  index.html

[root@node5 b.org]# cat  index.html

www.b.org

4、测试:

1、访问node5.a.com:

36090227959c57fd3793f74003ee606b.png

2、访问node5.a.org:

5ed25c848b58d8ea7600e28cc3067e5b.png

3、访问node5.a.org/Download:

f6c686d053ea4ae056d74ae601924513.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值