在 nginx 上正确安装网站但显示“无法获取/”

在 nginx 上正确安装网站但显示“无法获取/”

我实际上是使用 php 网站连接到另一个 nodejs 服务器,如客户端服务器端。经过多次错误和修复后,我得到了错误

404 Cannot GET /

就像服务器想要获取 index.php 文件但找不到或无法获取它。我在文件中没有任何错误或问题/var/log/nginx/error.log

也许还有其他日志我需要查看但我不知道在哪里。

服务器端 :

// server.js
const express = require('express');
const http = require('http');
const socketIO = require('socket.io');
const fs = require('fs');
const cors = require('cors'); 

const app = express();
app.use(cors());

const server = http.createServer(app);
const io = socketIO(server, {cors: {origin: 'https://lapignatomarseille.com:443',   methods: ['GET', 'POST'],   credentials: true}});

// Serveur WebSocket
io.on('connection', (socket) => {
  console.log('Un client s\'est connecté');
  
    // Écoute les changements dans le dossier "Images"
    fs.watch('Images', { recursive: true }, (eventType, filename) => {
        if (eventType === 'change' || eventType === 'rename') {
          // Émet un événement 'imageUpdated' aux clients connectés
          io.emit('imageUpdated', { filename });
          setTimeout(function() {io.emit('MenuOk',{ filename });}, 500);
        }
    });

  // Gérer la déconnexion du client
  socket.on('disconnect', () => {
    console.log('Un client s\'est déconnecté');
  });
});

// Serveur HTTP pour l'application web
const PORT = process.env.PORT || 8000;
server.listen(PORT, () => {
  console.log(`Serveur HTTP démarré sur le port ${PORT}`);
});

客户端脚本端:

<script>
    // Connexion WebSocket côté client pour les utilisateurs
    const socket = io.connect('http://localhost:8000'); // Mettez à jour l'URL du serveur WebSocket

    // Écoute des événements 'imageUpdated'
    socket.on('connect', (e) => {
        console.log('Client connecté ');
    });

    socket.on('imageUpdated', (data) => {
        console.log('Image mise à jour:', data.filename);

        // Commentez ou supprimez la ligne suivante pour éviter le rechargement automatique
        document.location.reload()
    });
    </script>

这是 lapignatomarseille.com.conf 的 nginx conf 文件:

server {
  listen 80;
  listen [::]:80;
  listen 443 ssl http2;
  listen [::]:443 ssl http2;
  server_name lapignatomarseille.com www.lapignatomarseille.com;

  ssl_certificate /etc/letsencrypt/live/lapignatomarseille.com/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/lapignatomarseille.com/privkey.pem;
  ssl_trusted_certificate /etc/letsencrypt/live/lapignatomarseille.com/chain.pem;
  ssl_stapling on;
  ssl_stapling_verify on;

  # Autres configurations SSL...

  location / {
    proxy_http_version 1.1;
    proxy_pass http://localhost:8000;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_cache_bypass $http_upgrade;
  }
}

server {
  listen 8080;
  listen [::]:8080;
  server_name lapignatomarseille.com www1.lapignatomarseille.com;
  root /home/lapignatomarseille/htdocs/lapignatomarseille.com;

  try_files $uri $uri/ /index.php?$args;
  index index.php index.html;

  location ~ \.php$ {
    include fastcgi_params;
    fastcgi_intercept_errors on;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    try_files $uri =404;
    fastcgi_read_timeout 3600;
    fastcgi_send_timeout 3600;
    fastcgi_param HTTPS "on";
    fastcgi_param SERVER_PORT 443;
    fastcgi_pass 127.0.0.1:18001;
    fastcgi_param PHP_VALUE "
error_log=/home/lapignatomarseille/logs/php/error.log;
memory_limit=512M;
max_execution_time=60;
max_input_time=60;
max_input_vars=10000;
post_max_size=64M;
upload_max_filesize=64M;
date.timezone=UTC+1;
display_errors=off;";
  }

  if (-f $request_filename) {
    break;
  }
}

我该怎么做才能使网站在访问网址时可见?我不知道我可以向您展示什么,所以请告诉我,我会更新问题。

谢谢阅读 !

相关内容