Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7651631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:33:22+00:00 2026-05-31T11:33:22+00:00

I have a Express.js (v 2.5.8) (node v0.6.12) server running on port 3100. It

  • 0

I have a Express.js (v 2.5.8) (node v0.6.12) server running on port 3100. It is front ended by Nginx, which proxies both http and https requests to port 3100.

I want to force certain urls over https. Here’s an example (app is my Express server):

app.get('/applyNow', ensureSec, secure.showApplication );

ensureSec is the function that I’m trying to use to check if connection is over ssl:

function ensureSec(req, res, next) {
    if (req.session.ssl == true) { 
        return next(); 
    } else {
        req.session.ssl = true;
        res.redirect('https://' + url.parse(req.headers.referer).host +
        url.parse(req.url).pathname);
    }
}

The redirect works but node (after it times out) throws an error saying `Cannot GET /applyNow

What’s the proper way of redirect to ssl?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T11:33:23+00:00Added an answer on May 31, 2026 at 11:33 am

    As I understand it, you are using nginx to negotiate SSL and proxying both http and https requests to your Express app. I would opt to solve this in nginx instead, if possible, but if nginx can’t know which paths should be protected (i.e. only available through https) or you want to do this in your express app for some other reason, here is some information:

    You should get the X-Forwarded-Proto from nginx, set to https only when the original protocol was https. Here’s how you do this in nginx:

    proxy_set_header X-Forwarded-Proto https;
    

    I would also forward the Host header:

    proxy_set_header Host $http_host;
    

    In your express app, check for that, or redirect to the host in the headers and the requested path (express parses that to req.path so you don’t have to):

    function ensureSec(req, res, next) {
        if (req.headers['x-forwarded-proto'] == 'https') { 
            return next(); 
        } else {
            res.redirect('https://' + req.headers.host + req.path);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a local server running on port 6868. Technically it's node.js-driven micro-site built
I have SQL Server Express and Visual Studio Web Developer Express running on my
I have a node.js server written in express and at a certain moment I
I'm running Nodejs and Apache alongside each other. node-http-proxy is listening on port 80
I have setup nginx as a front end to an node.js app. My nginx
I have an application up and running on Heroku with Express.js on Node.js with
I have the following in my node server using Express (truncated to the important
I want to route root route (http://server:5000/) in my node.js express.js application: When I
I have the following express node.js app. It's using the 'redis' npm package. app.get(/test,function(req,res){
It is possible in SQL Server Express have a log of all operations SELECT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.