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 6147713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:09:07+00:00 2026-05-23T19:09:07+00:00

I am using the following configuration for NGinx currently to test my app :

  • 0

I am using the following configuration for NGinx currently to test my app :

location / {
            # see if the 'id' cookie is set, if yes, pass to that server.           
            if ($cookie_id){
                proxy_pass http://${cookie_id}/$request_uri;                
                break;
            }

            # if the cookie isn't set, then send him to somewhere else
            proxy_pass http://localhost:99/index.php/setUserCookie;
        }

But they say “IFisEvil“. Can anyone show me a way how to do the same job without using “if”?
And also, is my usage of “if” is buggy?

  • 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-23T19:09:08+00:00Added an answer on May 23, 2026 at 7:09 pm

    There are two reasons why ‘if is evil’ as far as nginx is concerned. One is that many howtos found on the internet will directly translate htaccess rewrite rules into a series of ifs, when separate servers or locations would be a better choice. Secondly, nginx’s if statement doesn’t behave the way most people expect it to. It acts more like a nested location, and some settings don’t inherit as you would expect. Its behavior is explained here.

    That said, checking things like cookies must be done with ifs. Just be sure you read and understand how ifs work (especially regarding directive inheritance) and you should be ok.

    You may want to rethink blindly proxying to whatever host is set in the cookie. Perhaps combine the cookie with a map to limit the backends.

    EDIT: If you use names instead of ip addresses in the id cookie, you’ll also need a resolver defined so nginx can look up the address of the backend. Also, your default proxy_pass will append the request onto the end of the setUserCookie. If you want to proxy to exactly that url, you replace that default proxy_pass with:

    rewrite ^ /index.php/setUserCookie break;
    proxy_pass http://localhost:99;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have set up a openVPN tunnel using the following server side configuration: port
I am trying to host my service using following configuration. <system.serviceModel> <services> <service name=Test.MyService
I'm trying to get zc.buildout to install Gunicorn from source. Using the following configuration:
I am using Fluent NHibernate with an external 'hibernate.cfg.xml' file. Following is the configuration
I am using following storedprocedure set ANSI_NULLS ON set QUOTED_IDENTIFIER ON GO Alter PROCEDURE
i have a working solaris 10 server with ssh and NIS using the following
I'm using following code to open the web.config of my current web application. Configuration
i' m using BlazeDs. In services-config.xml we got following configuration of endPoint. <channel-definition id=any-amf
I'm using log4cxx and with the following configuration, I understand I can roll a
In my asp.net website i am using asp.net form authentication with following configuration <authentication

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.