skip to Main Content

I have a NODEJS+EXPRESS on my VPS with my domain name but can’t access to it.

https://mydomain1.com => 404 error

https://mydomain1.com:8080 => Everything works just fine !

What I want to do : Access to my website without port at url’s end like this :
https://mydomain1.com

App folder:

app
├── locales
├── public
│   ├── favicon
│   ├── icon
│   └── image
└── views
    └── pages

My server.js NODEJS website :

app.get('/test', (req, response) => {
    response.render('pages/test')
})//and a lot of other app.get page

const https = require('https');
var tls = require('tls')
var fs = require('fs')

const SSLoptions = {
    key: fs.readFileSync('key.pem'),
    cert: fs.readFileSync('cert.pem')
};

https.createServer(SSLoptions, app).listen(8080)

default file on /etc/nginx/site-available :

server {
        listen 443 ssl default_server;
        listen [::]:443 ssl default_server;

        root /var/www/html;

        index index.html index.htm index.nginx-debian.html;

        server_name mydomain1.com;

location / {
    proxy_pass http://127.0.0.1:8080;
    proxy_redirect off;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_set_header X-NginX-Proxy true;
}


server {
    if ($host = mydomain1.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    listen 80;
    listen [::]:80 ipv6only=on;

    server_name mydomain1.com;
    return 404; # managed by Certbot
}

nginf.conf on /etc/nginx/ :

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##
    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ##
    # SSL Settings
    ##

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

2

Answers


  1. Chosen as BEST ANSWER

    Thank you for answer. I copy/paste /etc/nginx/site-available/default to /etc/nginx/site-enabled/default/ and everything is working !


  2. Your nginx.conf is using site-enabled/* and you edited sites-available

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search