Quantcast
Channel: Active questions tagged ubuntu - Stack Overflow
Viewing all articles
Browse latest Browse all 6112

subpaths return 404 with nginx

$
0
0

I have a dockerized node js applicaiton on a ubuntu server with github ci/cd and i have setup reverse proxy with nginx and it works when i hit serverip but when i do something like serverip/aboutpage nginx return 404, so i tried hitting the docker container on my server with curl 0.0.0.0:8080/aboutpage and it return a valid response

here is the default file under etc/nginx/sites-available

root /var/www/html;        # Add index.php to the list if you are using PHP        index index.html index.htm index.nginx-debian.html;        server_name _;        location / {                proxy_pass http://172.17.0.2:8080; #docker container ip                 # First attempt to serve request as file, then                # as directory, then fall back to displaying a 404.                try_files $uri $uri/ =404;        }

Dockerfile

FROM node:22-alpineRUN mkdir -p /home/node/app/node_modules && chown -R node:node /home/node/appUSER nodeWORKDIR /home/node/appCOPY --chown=node:node package*.json .RUN npm installCOPY --chown=node:node . .EXPOSE 8080CMD [ "node", "server.js" ]

ci.yml

name: CI Pipelineon:  push:    branches: [ "main" ]jobs:  build:    runs-on: ubuntu-latest    steps:    - uses: actions/checkout@v4    - name: Login Dockerhub      env:        DOCKER_USERNAME: ${{secrets.DOCKER_USERNAME}}        DOCKER_PASSWORD: ${{secrets.DOCKER_PASSWORD}}      run: docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD    - name: Build the Docker image      run: docker build -t sm-api .    - name: Tag Docker local image      run: docker tag sm-api username/sm-api:latest    - name: Push to Dockerhub      run: docker push username/sm-api:latest

cd.yml

name: CD Pipelineon:  workflow_run:    workflows: ["CI Pipeline"]    types:      - completedjobs:  build:    runs-on: self-hosted    steps:    - name: Pull Docker image      run: sudo docker pull username/sm-api:latest    - name: Delete Old docker container      run: sudo docker rm -f sm-api-container || true    - name: Run Docker Container      run: sudo docker run -d -p 8080:8080 --name sm-api-container username/sm-api

my nodejs router index file

function MyRoutes(app, express){    const router = express.Router();    router.get('/', (req, res) => {        res.send('HomePage');      });    router.get('/about', (req, res) => {        res.send('about');      });      return router;}module.exports = {    WebRoutes};

everything works fine locally


Viewing all articles
Browse latest Browse all 6112

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>