nginx的简单应用

一、基于域名的虚拟主机

实现一台nginx的服务器上部署2个网站

[root@web-2 conf]# cd /usr/local/nginx-1/conf        进入配置文件目录

[root@web-2 conf]# vim nginx.conf        修改配置文件

 server {

        listen       80;

        server_name  www.feng.com;

        access_log   logs/feng.com.access.log;

        error_log    logs/feng.com.error.log;

        location / {

            root   html/feng;

            index  index.html index.htm;

        }

    }

    server {

        listen       80;

        server_name  www.wen.com;

        access_log   logs/wen.com.access.log;

        error_log    logs/wen.com.error.log;

        location / {

            root   html/wen;

            index  index.html index.htm;

        }

    }

[root@web-2 conf]# nginx -t        检查代码是否有问题

去创建网站首页

[root@web-2 nginx-1]# cd /usr/local/nginx-1/html        进入网页文件夹

[root@web-2 html]# mkdir wen  feng          新建wen和feng文件夹

[root@web-2 html]# ls

50x.html  feng  index.html  wen

[root@web-2 html]# cd feng

[root@web-2 feng]# vim index.html  新建首页文件

[root@web-2 feng]# cat index.html

welcome to feng's website

[root@web-2 feng]# cd ..

[root@web-2 html]# cd wen

[root@web-2 wen]# vim index.html        新建首页文件

[root@web-2 wen]# cat index.html

welcome to wen's website

[root@web-2 wen]# nginx  -s  reload        重启nginx服务

测试访问

[root@web-2 wen]# curl www.feng.com

welcome to feng's website

[root@web-2 wen]# curl www.wen.com

welcome to wen's website

二、在网页上提供下载服务

首先要在html文件夹中创建download文件夹,down文件夹中随便建几个文件

[root@web-2 html]# mkdir wendownload

[root@web-2 wendownload]# mkdir ppp

[root@web-2 conf]# cat nginx.conf        在配置文件中添加下载路径和服务

 server {
        listen       80;
        server_name  www.wen.com;
        access_log  logs/wen.com.access.log;
        error_log   logs/wen.com.error.log;
        location / {
            root   html/wen;
            index  index.html index.htm;
        }
         location /wendownload{
                autoindex on;
        } 
            
    }  

[root@web-2 conf]# nginx -s reload        重启服务

然后去网页检查是否成功,www.wen.com/download

三、隐藏nginx的版本

在nginx.conf配置文件中把server_tokens on改为off

四、开启状态统计功能

在nginx.conf配置文件中添加如图所示内容

重启服务后访问www.feng.com/sctatus

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值