簡體   English   中英

無法在 Nginx 中重定向

[英]Unable to Reidirect in Nginx

我向我的服務器添加了一個新網站(“thissite.online”),雖然我希望將其重定向到端口“6000”,但 NGINX 不斷將其重定向回端口“8000”。 如果我關閉端口 8000,它會導致 502(壞網關)。 我的代碼有什么問題嗎? 該網站是用 React 和 build 構建的

server {
    server_name admin.abc.tech www.admin.abc.tech;
    location / {
        proxy_pass http://127.0.0.1:8000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
        proxy_redirect off;
     }
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/admin.abc.tech/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/admin.abc.tech/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
    listen 80;
    server_name abc.tech www.abc.tech;
    location / {
        proxy_pass http://127.0.0.1:5000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
        proxy_redirect off;
     }
}
server {
    listen 80;
    server_name thissite.online www.thissite.online;
    location / {
        proxy_pass http://127.0.0.1:6000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
        proxy_redirect off;
     }
}
server {
    if ($host = admin.abc.tech) {
        return 301 https://$host$request_uri;
    } # managed by Certbot
    listen 80;
    server_name admin.abc.tech www.admin.abc.tech;
    return 404; # managed by Certbot
}

這是我的服務器代碼:這是我通常在啟動服務器應用程序時使用的代碼

const express = require ('express')

const app  = express()
const PORT  = process.env.PORT || 6000
const path = require('path')

require('dotenv').config()


app.use(express.json({ limit: '50mb' }));
app.use(express.urlencoded({ limit: '50mb', extended: true }));

app.use(require('./Routes/auth'))

app.use(express.static("client/build"));
  
app.get(/^\/(?!api).*/, (req, res) => {
    res.sendFile(path.join(__dirname, "client", "build", "index.html")); // relative path
  });

app.listen(PORT,()=>{
    console.log(`server connected http://localhost:${PORT}`);
})

代碼實際上是正確的,事實證明設置需要時間

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM