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 6月 3 22:32 index.html
drwxr-xr-x 2 root root 6 6月 3 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;
}
}
}