Htaccess on Nginx

82

NGINX doesn't have support for anything like .htaccess (Unless I'm mistaken) so you'll need to put the rules into an NGINX config file, probably within a virtual host.

A virtual host is the specific configuration for a domain, within the NGINX config it will look like

  server { # simple reverse-proxy
    listen       80;
    server_name  domain2.com www.domain2.com;
    access_log   logs/domain2.access.log  main;

    location / {
      proxy_pass      http://127.0.0.1:8080;
    }
  }

(Taken from the NGINX sample config)
So you would put your converted .htaccess rules within the location{} square brackets (Equivalent to Apache's ).
To give a full example, say I have some URL rewrites in my .htaccess file

#Enable URL Rewriting
RewriteEngine on

#Rewrite some pages
RewriteRule ^page/([0-9a-zA-Z_-]+).html$ /pagehander.php?page=$1 [QSA]

Running it through the converter I get

rewrite ^/page/([0-9a-zA-Z_-]+).html$ /pagehander.php?page=$1;

So I would put that in my NGINX server config like

  server { # simple reverse-proxy
    listen       80;
    server_name  domain2.com www.domain2.com;
    access_log   logs/domain2.access.log  main;

    location / {
rewrite ^/page/([0-9a-zA-Z_-]+).html$ /pagehander.php?page=$1;
      proxy_pass      http://127.0.0.1:8080;
    }
  }
Share:
82

Related videos on Youtube

user3891236
Author by

user3891236

Updated on September 18, 2022

Comments

  • user3891236
    user3891236 over 1 year

    MSVS 2010 , Windows 7

    I am using an API to access camera features.

    The following function displays a frame and saves it.

    void DisplayThread::OnBufferDisplay( PvBuffer *aBuffer )
    {
    
           mDisplayWnd->Display( *aBuffer ); //displaying frame 
    
    
    //Now let us try to save the frame with name of the form %Y%m%d%H%M%S.bmp
    
        system("mkdir D:\\ABCD" );  
                struct tm *tm;
                int count;
            time_t t;
            char str_time[20];
            t = time(NULL);
            tm = localtime(&t);
            strftime(str_time, sizeof(str_time), "%Y%m%d%H%M%S.bmp", tm); //name of the frame 
                char name[1000]; //sufficient space
             sprintf(name,"%s",str_time);
                char   path[]="D:\\ABCD";
                strcat(path,name); //path =path+"\\"+name;
            //  char* str=(char*)(void*)Marshal::StringToHGlobalAnsi(path);
        PvString lFilename( path );
                            PvString lCompleteFileName( lFilename );
    
     PvBufferWriter lBufferWriter; //The following function saves image
     PvResult lResult = lBufferWriter.Store( aBuffer, lCompleteFileName, PvBufferFormatBMP );
    
    
    }
    

    The name of the bmp file that is saved is of the form %Y%m%d%H%M%S.bmp

    The program builds perfectly fine , even display is coming correctly, but the following error message pops up:

    enter image description here

    It looks like something is wrong with the memory allocation with the variable 'name'.

    But I have allocated sufficient space, even then I am getting this error.

    Why it is happening ?

    Kindly let me know if more info is required to debug this.

    Note: The value returned by lBufferWriter.Store() is 'OK' (indicating that buffer/frame writing was successful), but no file is getting saved. I guess this is because of the run-time check failure I am getting.

    Please help.

    • Mat
      Mat over 9 years
      path is too small, it can only hold 7 chars (+ zero terminator)
    • user3891236
      user3891236 over 9 years
      @Mat Can you please suggest then , what is the best practice ? shall I allocate an array char path[1000] something like this?
    • Retired Ninja
      Retired Ninja over 9 years
      Your buffer needs to be large enough to hold the data you're trying to put into it. If you're on Windows, MAX_PATH is generally large enough for a filename.
    • user3891236
      user3891236 over 9 years
      @RetiredNinja Thanks for your comment. Could you please give a small code snippet or modify my code to explain this , as an answer? I will accept it as answer after verifying it.
  • Pranay Kumar
    Pranay Kumar almost 13 years
    How do you mean Virtual Host? Another guy told me also that but I don't understand it..
  • Toby Mao
    Toby Mao almost 13 years
    @Slaxxer Edited the post to give a bit more info.