
我實際上正在使用 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;
}
}
當我造訪該網址時,如何才能使該網站可見?我不知道我能向您展示什麼,所以請告訴我,我會更新問題。
謝謝閱讀 !