-
Hey. Im using Nginx to host my main website ( Connection steps:
Code: import * as fs from 'node:fs'
import * as http from 'node:http'
import * as path from 'node:path'
import * as dotenv from 'dotenv'
import express from 'express'
import api from './api/api'
dotenv.config({ path: path.resolve(path.join(__dirname, '../', '.env')) })
const config = {
PORT: 8080
}
const app: express.Express = express()
app.use('*', (req, res, next) => {
console.log(`Connection: ${req.socket.remoteAddress}:${req.socket.remotePort} [${req.originalUrl} - ${req.baseUrl} - ${req.url}]`)
next()
})
app.use('/api/test', (req, res) => {
res.send('Hello, test api')
})
app.use('/api', (req, res) => {
res.send('Hello, API!')
})
app.get('/', (req, res) => {
res.send('Hello World!')
})
app.listen(config.PORT, () => {
console.log(`Listening on port ${config.PORT}`)
}) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Perhaps its a more nginx problem, could you please try something like, server {
listen 80;
server_name www.my.domain.name.com;
location /api/ {
proxy_pass http://localhost:8080/;
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;
}
location / {
# Your other settings for the main website
}
} |
Beta Was this translation helpful? Give feedback.
Perhaps its a more nginx problem, could you please try something like,