【问题标题】:NGINX Error; 1 rewrite or internal redirection cycle while internally redirecting to "/index.html"NGINX 错误; 1 次重写或内部重定向循环,同时内部重定向到“/index.html”
【发布时间】:2022-02-11 19:00:28
【问题描述】:
2021/02/23 18:50:45 [error] 3476#3476: *1 rewrite or internal redirection cycle while internally redirecting to "/index.html", client: 192.168.0.50, server: _, request: "GET /search HTTP/1.1", host: "192.168.0.94", referrer: "http://192.168.0.94/"

我正在尝试使用 node.js 创建一个网站,因为我想在未来实现其他应用程序。我可以在我的 PC 上获取子目录,但是当我尝试在任何东西上使用时,我得到了这个错误。

这是我的配置:

server {
    listen 80;
    server_name _;

    error_log /var/log/nginx/personalsite.error.log;

    root /var/www/html/;
    index search.html;

    location / {
        proxy_pass http://localhost:3000;
        try_files $uri $uri/ =404;
    }

    location ^~ /search/ {
        alias /var/www/html/views/;
    }

    location ^~ /results/ {
        alias /var/www/html/views/;
    }

}

还有我的 app.js:

const express = require('express');
const path = require('path');

// Init App
const app = express();

// Load View Engine
app.use('/css', express.static(path.join(__dirname, 'css')));
app.use('/js', express.static(path.join(__dirname, 'js')));

app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');

// Web Routes
app.engine('html', require('ejs').renderFile);
app.use(express.urlencoded({extended: true}));

app.get('/', (req, res) => {
    res.render('index.html');
});

app.get('/search', (req, res) => {
    res.render('search.html');
});

app.get('/results', (req, res) => {
    res.render('results.html');
});

app.get('/found', (req, res) => {
    res.render('found.html');
});

app.get('/player', (req, res) => {
    res.render('player.html');
});

// Start Server
app.listen('3000', () => {
    console.log('Listening on port 3000!');
});

如果您知道为什么这是对我有很大帮助的问题,谢谢!

【问题讨论】:

    标签: node.js nginx


    【解决方案1】:

    尝试替换

    try_files $uri $uri/ =404;
    

     try_files $uri $uri/ index.html;
    

    阅读更多Nginx rewrite or internal redirection cycle while internally redirecting to "/index.html"

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-06-21
      • 1970-01-01
      • 2017-04-05
      • 2014-04-25
      • 2014-03-28
      • 2011-05-16
      • 2013-08-21
      • 1970-01-01
      相关资源
      最近更新 更多