1
0
mirror of https://gitee.com/tawords/tawords-docs synced 2025-01-31 13:00:27 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
tawords-docs/docs/manual/internal/pseudo-static.md
2021-08-18 18:32:54 +08:00

69 lines
1.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

> 使用宝塔配置
## 配置文件
删除 `|LICENSE|README.md`
```nginx
#禁止访问的文件或目录
# location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md) # 修改这一行
location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project) # 为这一行
{
return 404;
}
```
## 伪静态
> 2021.08.18更新
http跳转httpswww跳转@;访问二级域名指向网站的二级路径
```nginx
# http跳转https
if ($server_port !~ 443){
rewrite ^(/.*)$ https://$host$1 permanent;
}
# 👇www跳转@
if ($host ~* "^www\.(.*?\..*?)$") # if ($host = 'www.reciteword.com')
{
# $host = www.reciteword.com
# $1 = reciteword.com
return 301 https://$1; # https://reciteword.com$request_uri;
}
location ~ {
index index.php index.html index.htm;
# 👇访问二级域名指向网站的二级路径
# 定义一个变量用于保存正则表达式的匹配值Nginx不允许嵌套if
set $param "";
if ($http_host ~* "^(.*?)\..*?\..*?$") # if ($http_host ~* "^(.*?)\.reciteword\.com$")
{
set $param $1; # $param 是正则表达式的匹配值
}
# 定义默认指向二级路径(需要考虑首页)
set $domain "@";
if ($param != "") # 非首页
{
set $domain $param; # 指向网站的二级路径
}
# 到目前为止,已经完成获取 xx.reciteword.com 的 xx 信息了(如果是 reciteword.com 则为@
# 接下来是设置网站的 root需要考虑文档 docs 是独立的目录)
if ($domain != "docs")
{
root /www/wwwroot/tawords-server-side/$domain;
}
if ($domain = "docs")
{
root /www/wwwroot/tawords-docs/docs; # docs 为仓库 docs/ 文件夹
}
}
# autoindex on; # 自动索引(测试时使用,线上环境勿开)
```