Join the community today
Register Now

NextJS Node

Discussion in 'Install & Upgrades or Pre-Install Questions' started by ahmed, Sep 10, 2025.

  1. ahmed

    ahmed Active Member

    404
    49
    28
    Feb 21, 2017
    Ratings:
    +63
    Local Time:
    4:01 AM
    Hi


    Any good approach to install Nextjs on the same centmin server and proxying Nginx 443--->3000 port
     
  2. ahmed

    ahmed Active Member

    404
    49
    28
    Feb 21, 2017
    Ratings:
    +63
    Local Time:
    4:01 AM
    Code:
    curl -i http://localhost:3000/_next/static/chunks/8041-bb401ecfccdba067.js
    HTTP/1.1 200 OK
    Cache-Control: public, max-age=31536000, immutable
    Accept-Ranges: bytes
    Last-Modified: Thu, 11 Sep 2025 00:12:33 GMT
    ETag: W/"3254-199361de7c7"
    Content-Type: application/javascript; charset=UTF-8
    Content-Length: 12884
    Vary: Accept-Encoding
    Date: Thu, 11 Sep 2025 01:21:57 GMT
    Connection: keep-alive
    Keep-Alive: timeout=5
    This curl is working fine

    but on the 443 https it show 404 for all JS files

    this is my addtions to location section in the 443 server segment
    Code:
     proxy_pass http://localhost:3000; # Forward requests to the application on port 3000
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection 'upgrade';
      proxy_set_header Host $host;
      proxy_cache_bypass $http_upgrade;
      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;

    any help please
     
  3. ahmed

    ahmed Active Member

    404
    49
    28
    Feb 21, 2017
    Ratings:
    +63
    Local Time:
    4:01 AM
    by the way it worked fine before lets encrypt SSL (dual cert) implementation ob the domain
     
    Last edited: Sep 11, 2025
  4. ahmed

    ahmed Active Member

    404
    49
    28
    Feb 21, 2017
    Ratings:
    +63
    Local Time:
    4:01 AM
    Code:
        location / {
            proxy_pass http://127.0.0.1:3000;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;
        }
    
        location /_next/ {
            proxy_pass http://127.0.0.1:3000;
            proxy_http_version 1.1;
            proxy_set_header Host $host;
        }
    
        location /static/ {
            proxy_pass http://127.0.0.1:3000;
            proxy_http_version 1.1;
            proxy_set_header Host $host;
        }
    
        location /public/ {
            proxy_pass http://127.0.0.1:3000;
            proxy_http_version 1.1;
            proxy_set_header Host $host;
        }
    
        location = /favicon.ico {
            proxy_pass http://127.0.0.1:3000;
        }
    
        location = /robots.txt {
            proxy_pass http://127.0.0.1:3000;
        }
    
    #optional
        real_ip_header X-Forwarded-For;
        add_header X-Frame-Options SAMEORIGIN;
        add_header X-XSS-Protection "1; mode=block" always;
        add_header X-Content-Type-Options nosniff always;
    }
    
    it worked with the above location change ,....but merging with ssl vhost fails...any idea?
     
  5. ahmed

    ahmed Active Member

    404
    49
    28
    Feb 21, 2017
    Ratings:
    +63
    Local Time:
    4:01 AM
    Code:
    nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed
     
  6. ahmed

    ahmed Active Member

    404
    49
    28
    Feb 21, 2017
    Ratings:
    +63
    Local Time:
    4:01 AM
    I did not touch this file..maybe from autoprotect? they are empty for the domains...how to debug?
     
  7. eva2000

    eva2000 Administrator Staff Member

    58,905
    12,490
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +19,122
    Local Time:
    12:01 PM
    Nginx 1.31.x
    MariaDB 10.x/11.4+/12.3+
    When you create a new nginx vhost domain via centmin.sh menu option 2 or menu option 22 or via /usr/bin/nv cli command line, you will create the Nginx vhost files and directories. You will get an outputted the path location where it will create the domain name's vhost conf file named newdomain.com.conf (and newdomain.com.ssl.conf if you selected yes to self signed SSL)
    • Nginx vhost conf path will be at /usr/local/nginx/conf/conf.d/newdomain.com.conf
    • Nginx HTTP/2 SSL vhost conf path will be at /usr/local/nginx/conf/conf.d/newdomain.com.ssl.conf
    • Nginx Self-Signed SSL Certificate Directory at /usr/local/nginx/conf/ssl/newdomain.com
    • Vhost public web root will be at /home/nginx/domains/newdomain.com/public
    • Vhost log directory will be at /home/nginx/domains/newdomain.com/log
    Please post the contents of /usr/local/nginx/conf/conf.d/newdomain.com.conf and if applicable /usr/local/nginx/conf/conf.d/newdomain.com.ssl.conf wrapped in CODE tags (outlined at How to use forum BBCODE code tags) and how you step by step setup nextjs and nginx vhosts and nginx config changes

    what is output of these commands in ssh
    Code (Text):
    curl -I https://domain.com
    

    Code (Text):
    curl -I https://www.domain.com
    

    Code (Text):
    curl -I http://domain.com
    

    Code (Text):
    curl -I http://www.domain.com
    

    wrap output in CODE tags
     
  8. ahmed

    ahmed Active Member

    404
    49
    28
    Feb 21, 2017
    Ratings:
    +63
    Local Time:
    4:01 AM
    Code:
    HTTP/2 521
    date: Thu, 11 Sep 2025 16:22:38 GMT
    content-type: text/html; charset=UTF-8
    server: cloudflare
    cf-ray: 97d8814d6af87aa7-AMS
    cache-control: private, max-age=0, no-store, no-cache, must-revalidate, post-check=0, pre-check=0
    expires: Thu, 01 Jan 1970 00:00:01 GMT
    set-cookie: cf_ob_info=521:97d8814d730e7aa7:AMS; path=/; expires=Thu, 11-Sep-25 16:23:08 GMT
    set-cookie: cf_use_ob=443; path=/; expires=Thu, 11-Sep-25 16:23:08 GMT
    strict-transport-security: max-age=0
    cf-apo-via: origin,host
    referrer-policy: same-origin
    x-frame-options: SAMEORIGIN
    report-to: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v4?s=JuWpdIiohL27l5B3yWizBTPfa%2Ft24uu6wUtlscZmESgEAAFMla8H2HdBzI4XFZusYYBfjYLTT2SEN23k%2BYrV3fogEr8BUGIJ9%2FDzRIujO50XAn11cpBl0F2vUjO2zjPk6c%2BtEw%3D%3D"}],"group":"cf-nel","max_age":604800}
    nel: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
    speculation-rules: "/cdn-cgi/speculation"
    alt-svc: h3=":443"; ma=86400
    server-timing: cfL4;desc="?proto=TCP&rtt=4915&min_rtt=4886&rtt_var=1392&sent=6&recv=8&lost=0&retrans=0&sent_bytes=3407&recv_bytes=826&delivery_rate=858536&cwnd=254&unsent_bytes=0&cid=d13f0a033e670ad7&ts=44&x=0"
     
  9. ahmed

    ahmed Active Member

    404
    49
    28
    Feb 21, 2017
    Ratings:
    +63
    Local Time:
    4:01 AM
    Code:
    HTTP/1.1 301 Moved Permanently
    Date: Thu, 11 Sep 2025 16:23:57 GMT
    Content-Type: text/html
    Content-Length: 167
    Connection: keep-alive
    Cache-Control: max-age=3600
    Expires: Thu, 11 Sep 2025 17:23:57 GMT
    Location: https://test.domain/
    Report-To: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v4?s=f28XZv0sOcdZEa%2FXcTQ1H9w3M2aGVO6qVivNB9U1PpFztU3zfT340rkQP0bOcmYrcJqmqVM%2BIvjFk3VLq%2F5L4yj%2BAQclguq5qE1LJPCBCRD6CwWyHDEb7XPgsIoCapSH3NyuDA%3D%3D"}],"group":"cf-nel","max_age":604800}
    NEL: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
    speculation-rules: "/cdn-cgi/speculation"
    Server: cloudflare
    CF-RAY: 97d883383a4c0e00-AMS
    alt-svc: h3=":443"; ma=86400
    server-timing: cfL4;desc="?proto=TCP&rtt=4633&min_rtt=4633&rtt_var=2316&sent=1&recv=3&lost=0&retrans=0&sent_bytes=0&recv_bytes=83&delivery_rate=0&cwnd=249&unsent_bytes=0&cid=0000000000000000&ts=0&x=0"
     
  10. ahmed

    ahmed Active Member

    404
    49
    28
    Feb 21, 2017
    Ratings:
    +63
    Local Time:
    4:01 AM
    since it is already a subdomain so no www
     
  11. ahmed

    ahmed Active Member

    404
    49
    28
    Feb 21, 2017
    Ratings:
    +63
    Local Time:
    4:01 AM
    looks like it was error in that specific site vhost...when deleted all fixed now...
     
  12. ahmed

    ahmed Active Member

    404
    49
    28
    Feb 21, 2017
    Ratings:
    +63
    Local Time:
    4:01 AM

    what is the best way to include that in the vhost...I need to create a vhost file and put include that file inside ssl.vhost file and the normal vhost
     
  13. ahmed

    ahmed Active Member

    404
    49
    28
    Feb 21, 2017
    Ratings:
    +63
    Local Time:
    4:01 AM
    Code:
     location / {
            proxy_pass http://127.0.0.1:3000;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;
        }
    
        location /_next/ {
            proxy_pass http://127.0.0.1:3000;
            proxy_http_version 1.1;
            proxy_set_header Host $host;
        }
    
        location /static/ {
            proxy_pass http://127.0.0.1:3000;
            proxy_http_version 1.1;
            proxy_set_header Host $host;
        }
    
        location /public/ {
            proxy_pass http://127.0.0.1:3000;
            proxy_http_version 1.1;
            proxy_set_header Host $host;
        }
    
        location = /favicon.ico {
            proxy_pass http://127.0.0.1:3000;
        }
    
        location = /robots.txt {
            proxy_pass http://127.0.0.1:3000;
        }
    installed a new domain and added this code as it is to the ssl and non-ssl vhost
     
  14. ahmed

    ahmed Active Member

    404
    49
    28
    Feb 21, 2017
    Ratings:
    +63
    Local Time:
    4:01 AM
    Code:
    [16:52][root@centmin-doha feedback]# curl -i http://domain
    curl: (7) Failed to connect to domain port 80: Connection refused
     
  15. ahmed

    ahmed Active Member

    404
    49
    28
    Feb 21, 2017
    Ratings:
    +63
    Local Time:
    4:01 AM
    Code:
    TCP_IN = "20,21,22,25,53,853,80,110,143,443,465,587,993,995,1110,1186,1194,81,9418,30001:50011"
    TCP_OUT = "8080,2525,465,1110,1194,9418,3306,20,21,22,25,53,853,80,110,113,443,587,993,995"
    UDP_IN = "67,68,1110,33434:33534,20,21,53,853,80,443"
    UDP_OUT = "67,68,1110,33434:33534,443,20,21,53,853,113,123"
    TCP6_IN = "20,21,22,25,53,853,80,110,143,443,465,587,993,995,1110,1186,1194,81,9418,30001:50011"
    TCP6_OUT = "8080,2525,465,3306,20,21,22,25,53,853,80,110,113,443,587,993,995"
    UDP6_IN = "20,21,53,853,80,443"
    UDP6_OUT = "20,21,53,853,113,123"
    ports are open in firewall and in google firewall
     
  16. ahmed

    ahmed Active Member

    404
    49
    28
    Feb 21, 2017
    Ratings:
    +63
    Local Time:
    4:01 AM
    I'm close to the fix...however there is a conflict in the
    location = /robots.txt {
    proxy_pass http://127.0.0.1:3000;
    }

    with the

    location = /robots.txt { access_log off; log_not_found off; }


    in the file /usr/local/nginx/conf/drop.conf
     
  17. ahmed

    ahmed Active Member

    404
    49
    28
    Feb 21, 2017
    Ratings:
    +63
    Local Time:
    4:01 AM
    Code:
    [19:12][root@centmin-new feedback]# curl -I https://domain
    HTTP/2 200
    date: Thu, 11 Sep 2025 19:12:30 GMT
    content-type: text/html; charset=utf-8
    vary: Accept-Encoding
    vary: rsc, next-router-state-tree, next-router-prefetch, next-router-segment-prefetch, Accept-Encoding
    link: </_next/static/media/2dc625304a276794-s.p.woff2>; rel=preload; as="font"; crossorigin=""; type="font/woff2"
    x-powered-by: centminmod
    cache-control: private, no-cache, no-store, max-age=0, must-revalidate
    server: nginx centminmod
    x-xss-protection: 1; mode=block
    x-content-type-options: nosniff
    
    [19:12][root@centmin-new feedback]# curl -I http://domain
    HTTP/1.1 200 OK
    Date: Thu, 11 Sep 2025 19:13:08 GMT
    Content-Type: text/html; charset=utf-8
    Content-Length: 6375
    Last-Modified: Thu, 11 Sep 2025 17:57:42 GMT
    Connection: keep-alive
    Vary: Accept-Encoding
    ETag: "68c30d96-18e7"
    Server: nginx centminmod
    X-Powered-By: centminmod
    X-Xss-Protection: 1; mode=block
    X-Content-Type-Options: nosniff
    Accept-Ranges: bytes

    now it works but still not all the contents are loaded although I addedd them into the ssl vhost with an include file

    Code:
      GNU nano 5.6.1                                                                                                                                      /usr/local/nginx/conf/next.conf                                                                                                                                               
        location / {
            proxy_pass http://127.0.0.1:3000;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;
    
    
            include /usr/local/nginx/conf/503include-only.conf;
    
    # block common exploits, sql injections etc
            include /usr/local/nginx/conf/block.conf;
    
    
        }
    
        location /_next/ {
            proxy_pass http://127.0.0.1:3000;
            proxy_http_version 1.1;
            proxy_set_header Host $host;
        }
    
        location /static/ {
            proxy_pass http://127.0.0.1:3000;
            proxy_http_version 1.1;
            proxy_set_header Host $host;
        }
    
        location /public/ {
            proxy_pass http://127.0.0.1:3000;
            proxy_http_version 1.1;
            proxy_set_header Host $host;
        }
    
        location = /favicon.ico {
            proxy_pass http://127.0.0.1:3000;
        }
    
        location = /robots.txt {
            proxy_pass http://127.0.0.1:3000;
        }
    
     
  18. ahmed

    ahmed Active Member

    404
    49
    28
    Feb 21, 2017
    Ratings:
    +63
    Local Time:
    4:01 AM
    Code:
    server {
        listen 80;
        server_name test.domain www.test.domain;
    
        location / {
            proxy_pass http://127.0.0.1:3000;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;
        }
    
        location /_next/ {
            proxy_pass http://127.0.0.1:3000;
            proxy_http_version 1.1;
            proxy_set_header Host $host;
        }
    
        location /static/ {
            proxy_pass http://127.0.0.1:3000;
            proxy_http_version 1.1;
            proxy_set_header Host $host;
        }
    
        location /public/ {
            proxy_pass http://127.0.0.1:3000;
            proxy_http_version 1.1;
            proxy_set_header Host $host;
        }
    
        location = /favicon.ico {
            proxy_pass http://127.0.0.1:3000;
        }
    
        location = /robots.txt {
            proxy_pass http://127.0.0.1:3000;
        }
    
         real_ip_header X-Forwarded-For;
        add_header X-Frame-Options SAMEORIGIN;
        add_header X-XSS-Protection "1; mode=block" always;
        add_header X-Content-Type-Options nosniff always;
    }

    this is a manul edit that works fine on port 80

    how to make it good for modfied nginx
     
    Last edited: Sep 12, 2025
  19. eva2000

    eva2000 Administrator Staff Member

    58,905
    12,490
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +19,122
    Local Time:
    12:01 PM
    Nginx 1.31.x
    MariaDB 10.x/11.4+/12.3+
    Centmin Mod is provided as is. Folks are free to help each other on the forums. Try the following as a starter and adjust as needed

    Create a new /usr/local/nginx/conf/nextjs_upstream.conf include file with - adjust to your nextjs app port and/or add multiple upstream contexts with different names (nextjs_upstream) and app ports to include file. Place /usr/local/nginx/conf/nextjs_upstream.conf include file into /usr/local/nginx/conf/nginx.conf with other include files within http{} context
    Code (Text):
    upstream nextjs_upstream {
        server 127.0.0.1:3001;
        keepalive 64;
    }

    You only need HTTPS nginx vhost config /usr/local/nginx/conf/conf.d/yourdomain.com.ssl.conf to work with and remove non-HTTPS nginx vhost /usr/local/nginx/conf/conf.d/yourdomain.com.conf. Where proxy_pass upstream name (nextjs_upstream) is from /usr/local/nginx/conf/nextjs_upstream.conf defined include file previously created
    Code (Text):
        #Serve static assets directly if you like (Next outputs .next/static and public/)
        # Adjust paths if you deploy in a different directory
        root /home/nginx/domains/yourdomain.com/public;  # keep if you also use /public
        location ^~ /_next/static/ {
            alias /path/to/app/.next/static/;
            access_log off;
            expires 30d;
            add_header Cache-Control "public, max-age=2592000, immutable";
        }
    
        # Images (Next/Image) and everything else -> Next server
        location / {
            proxy_http_version 1.1;
            proxy_set_header Connection "";
            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_pass http://nextjs_upstream;
            proxy_read_timeout 60s;
            proxy_connect_timeout 60;
    
            # Websocket support (for dev or if using any WS features)
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
        }
    
        location ~ /.well-known {
            allow all;
        }
    

    In the same HTTPS nginx vhost config file at /usr/local/nginx/conf/conf.d/yourdomain.com.ssl.conf, add a 2nd server{} context for redirect for non-https to https as outlined at centminmod.com/nginx_domain_dns_setup.html#httpsredirect - pay attention to different way if you want redirect target being www version instead of non-www and vice versa and that the target version www or non-www is the only version listed in server_name for the 2nd/main server {} context or, instead you can do it straight from Cloudflare via rewrite rule or setting always use HTTPS
    Code (Text):
    server {
        listen 80;
        server_name yourdomain.com www.yourdomain.com;
        return 301 https://$host$request_uri;
    }

    Changing server_name values as needed.

    And if using Cloudflare, ensure you use Cloudflare DNS API domain validation method for Letsencrypt SSL certificate issuance on Centmin Mod Nginx side with Cloudflare SSL mode set to either Cloudflare Full SSL or Full Stirct SSL mode.

    Adjust ports and nginx web root path (root /home/nginx/domains/yourdomain.com/public;) and location contexts as needed.
     
  20. ahmed

    ahmed Active Member

    404
    49
    28
    Feb 21, 2017
    Ratings:
    +63
    Local Time:
    4:01 AM
    thanks a lot

    this goes to the /usr/local/nginx/conf/nextjs_upstream.conf file


    and this added to the yourdomain.com.ssl.conf