整理的一些常用到的 Nginx 配置
发表于:2022-02-10 17:42:41浏览:2515次
#伪静态配置
#Laravel
location / {
try_files $uri $uri/ /index.php$is_args$query_string;
}#ThinkPhp
location / {
if (!-e $request_filename){
rewrite ^(.*)$ /index.php?s=$1 last; break;
}
}#Vue History
location / {
try_files $uri $uri/ /index.html;
}#设置代理【简单版】
location /document
{
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto $scheme;
#此处配置 程序的地址和端口号
proxy_pass http://127.0.0.1:8181/;
}#设置 Nginx 访问日志
启动 nginx 时 会自动创建文件
access_log /www/wwwlogs/host.com.log; error_log /www/wwwlogs/host-error.com.log;
#设置 当前域名映射目录
root /www/wwwroot/host.com;
#监听多端口
server
{
listen 80;
listen 8081;
...
}#设置域名地址
server_name host.com;
#根据正则条件
被匹配域名 : http://host.com/TR1699043296-web.png
location ~ ^.*(TR.*)\.png$
{
proxy_pass http://127.0.0.1:9501;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}#根据后缀条件
location ~ .*\.(js|css)?$
{
# 过期时间
expires 12h;
# 开启日志
error_log off;
# /dev/null 忽略
access_log /dev/null;
}#文件不存在的时候指向另外一个站点
始发站点
location ~ ^.*(TR.*)\.(png|pdf)$
{
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
if (!-e $request_filename) {
proxy_pass http://127.0.0.1:9501;
}
}目标站点
location ~ ^.*(TR.*)\.(png|pdf)$
{
root /www/wwwroot/project;
}#PDF 浏览器加载
if ($request_filename ~* ^.*(TR.*)\.pdf$){
add_header Content-Disposition attachment;
}栏目分类全部>
推荐文章
- 解决composer install遇到:Your requirements could not be resolved to an installable set of packages
- windows批处理,批量替换文件、文件夹名中的空格
- vue - element-ui -> el-tag 标签状态
- php 多维数组指定某个值作为键
- win10系统重装应用商店:安装路径不存在 该怎么办?
- 清空 /var/log/journal 文件的方法
- Linux下搭建SVN服务器及自动更新项目文件到web发布目录(www)
- 微信H5版使用php Ffmpeg将微信录音amr转mp3
- TP6便捷快速查询日、月、年数据的方法
- 通过js实现button按钮间隔一分钟可点击
