Nginx作为下载站点

 grep -Ev '^$|#' /usr/local/nginx/conf/nginx.conf > /opt/nginx.txt
cat /opt/nginx.txt > /usr/local/nginx/conf/nginx.conf
用上面的指令提取最小化的配置文件
vim /usr/local/nginx/conf/nginx.conf
[root@localhost ~]# cat /usr/local/nginx/conf/nginx.conf
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  localhost;
        location / {
            root   html;
            index  index.html index.htm;
        }
        location /wu
{
alias wucg.com;
}

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

进入配置文件
填入关键信息测验网站是否能执行(alias)

location /wu
{
alias wucg.com;
}

创建需要的网页目录与网页信息

root@localhost:# mkdir wucg.com
root@localhost:# echo "<h1>wuwuwuwuwuwu</h1>" > wucg.com/index.html
root@localhost:# cat wucg.com/index.html
<h1>wuwuwuwuwuwu</h1>

查看配置文件语法是否正确并重启服务

root@localhost:/usr/local/nginx# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
root@localhost:/usr/local/nginx# /usr/local/nginx/sbin/nginx -s reload
从浏览器测验

在这里插入图片描述

填入关键信息测验网站是否能执行(root)

location /txt
{
root text;
}
vim /usr/local/nginx/conf/nginx.conf
[root@localhost ~]# cat /usr/local/nginx/conf/nginx.conf
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  localhost;
        location / {
            root   html;
            index  index.html index.htm;
        }
        location /txt
{
root text;
}
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}
创建需要的网页目录与网页信息
root@localhost:/usr/local/nginx# mkdir text
root@localhost:/usr/local/nginx# echo "<h1>gangganggangganggang</h1>" > text/index.htmlroot@localhost:/usr/local/nginx# cat text/index.html
<h1>gangganggangganggang</h1>

在这里插入图片描述

只新建一个text目录无法满足访问需求还需要在text目录下新建一个txt目录才行
root@localhost:/usr/local/nginx# cd text/
root@localhost:/usr/local/nginx/text# mkdir txt
root@localhost:/usr/local/nginx/text# ll
总用量 4
-rw-r--r-- 1 root root 30  63 22:32 index.html
drwxr-xr-x 2 root root  6  63 22:37 txt
root@localhost:/usr/local/nginx/text# cp -av index.html txt/
'index.html' -> 'txt/index.html'

新建好后再次用浏览器查看,浏览器一出现设置好的信息。

在这里插入图片描述

网页显示没用问题后,在回到配置文件内将一下内容填写进去,即可实现作为下载站点的需求

### wcg 20240603 -begin
    location /wcg {   
        #alias html;  # 替换为你的文件存储路径             
        root html;  # 替换为你的文件存储路径 
        #autoindex on;  # 开启目录浏览
        #autoindex_exact_size off;  # 显示文件的大概大小
        #autoindex_localtime on;  # 显示文件的服务器时间
        #charset utf-8,gbk;  # 解决中文目录乱码问题
### wcg 20240603 -begin

配置文件具体信息:

[root@wcg ~]# cat /usr/local/nginx/conf/nginx.conf
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  localhost;
        location / {
            root   html;
            index  index.html index.htm;
        }


### wcg 20240603 -begin
    location /wcg {  
        #alias html;  # 替换为你的文件存储路径  
        root html;  # 替换为你的文件存储路径  
        #autoindex on;  # 开启目录浏览  
        #autoindex_exact_size off;  # 显示文件的大概大小  
        #autoindex_localtime on;  # 显示文件的服务器时间  
        #charset utf-8,gbk;  # 解决中文目录乱码问题 
### wcg 20240603 -begin
}




location /v {
	
	alias v.hanyw.com;
}



        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值