Nginx Configuration Tips for Windows

Someone asked for more specific guidance on troubleshooting nginx on Windows for my plaso Kibana install walkthrough. Just a quickie on that topic.

Instead of double-clicking nginx.exe to run, try running from a command line. It’s very important to run the executable from it’s directory, not with a path in front of it – nginx will look for the folders for dependencies where it’s run, not the path that nginx.exe actually lives.

> cd \path\to\nginx\dir
\path\to\nginx\dir> nginx.exe

Does it run successfully? If it doesn’t do you get an error message about can’t find directory or can’t create error.log?

Try a different config, like the one below (I wish wp would preserve my formatting…):

#user nobody;
worker_processes 1;
error_log off;
#logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
 worker_connections 1024;
}
http {
 include mime.types;
 default_type application/octet-stream;
 #access_log logs/access.log main;
 sendfile on;
 #tcp_nopush on;
 #keepalive_timeout 0;
 keepalive_timeout 65;
 #gzip on;
 server {
 listen 80;
 server_name localhost;
 #charset koi8-r;
 #access_log logs/host.access.log main;
 location / {
 root /html;
 index index.html index.htm;
 }
 #error_page 404 /404.html;
 # redirect server error pages to the static page /50x.html
 #
 error_page 500 502 503 504 /50x.html;
 location = /50x.html {
 root html;
 }
 }
}

This is the most vanilla config I could cook up, mostly it’s the default config with nginx – the other Kibana-specific config was meant to account for user auth etc for dashboard access. If you’re doing a local vanilla install AND you don’t care about security, try this approach and then build security on top of it.

X-Plane 10 Installation on Ubuntu 12.x (stable)

EDIT: Removed sudo from the actual run and install as they are not necessary if you are running as a non-restricted user (which I am not here), and you are giving unnecessary permissions. Michal is absolutely right, udev rules are a better way to go…the reason I have no qualms about using sudo on my machine is because it’s a closed system, and x-plane is the only application running on it. For an example of udev rules (this is for the joystick but you can also use this on other devices if they’re giving you trouble) check here: http://developer.x-plane.com/2012/09/linux-joystick-permissions/ or at the x-plane forums. Thanks, Michal!

I built a machine to run x-plane 10…it’s so graphically intensive I wanted to give it its own box. Comment or message for the spec if you’re interested. Here’s a few things you may need to do to get it running. I’m going to do this from the beginning and assume you haven’t installed anything on this machine before. Obviously if you have a working machine, you’ll only need to check for dependencies and run the installer.

1) Install Ubuntu. Download the operating system onto a flash drive or dvd, and install it. Check your machine’s BIOS settings to see what you can boot off of – should be something like “Boot Order” on the menu. If you see USB options there, you can boot off of a formatted flash drive. Otherwise you’ll have to throw the iso on a dvd and boot from the optical drive.

2) Update Ubuntu. Do this:

~sudo apt-get update
~sudo apt-get dist-upgrade

After you do apt-get update the update center may open up on Ubuntu and ask if you want to update, this is fine.

2) a) You may need to install some drivers if it’s a brand new build like mine…I have an AMD processor on a ASRock motherboard. You’ll need to hunt down the proper drivers and install them this way:

Go to System Settings > Hardware > Additional Drivers OR you can just go to the icon in the upper left and type additional drivers, should bring you to the same place.

Just submit and you’ll see if there are drivers that you can snag. My AMD drivers were there, no thinking required (thanks, Ubuntu?).

3) Get a few dependencies. The wiki in step 5 shows you how to do this on a gui if you need one. You need ia32libs if you’re running 64 bit, like many people have mentioned and you need OpenAL for sound. Do this:

~sudo apt-cache search ia32

Find the current ia32libs …may be called something similar

~sudo apt-get install ia32libs

Then:

~sudo apt-cache search openal

Find the current openal…I think mine looked like libopenal1 or something like that

~sudo apt-get install xxxxxxx

4) Restart if prompted (probably for drivers)

5) Now we’re going to follow X-Plane’s (very well-written) installation wiki here: http://wiki.x-plane.com/Linux_Installation_Walkthrough.

This is copied from them, modified where I’ve bolded the text:

“Getting the installer to the desktop

First, we’ll copy the X-Plane Linux installer to the desktop. This is necessary because we will need to remove Disc 1 in the course of installing the scenery. Linux doesn’t like having the installer present only in memory (as would be the case in a Windows or Mac installation), so we’ll pacify it by moving it to the hard drive.

In the past, there were issues with the mounting of the Linux discs; in the distributions described here, this is no longer the case. The installation discs mount correctly and are usable without any extra input. More information can be found on the DVD Problems page.

Please note that the installation steps presented here are for the 9.00 set of gray-colored discs. When using a different set of discs (such as the older beta discs or the discs purchased in a retail store) it may be necessary to download the Linux installer from the DVD Installers page. Edit: The X-Plane 10 updates are here: http://www.x-plane.com/downloads/x-plane_10_installer-updater/

Gathering the required libraries

After getting the installer on the desktop, we will download any software libraries needed by X-Plane but not present on the system. On a 64-bit system, this usually means downloading the 32-bit versions of Mesa (a free implementation of the OpenGL graphics library) and OpenAL (an audio library). Some 32-bit systems will already have these installed.

To find out what libraries the installer will need, open the terminal (also called the command line) and navigate to where the installer was saved. Assuming that the installer is on the desktop, and that the terminal opens in the [user name] folder, this is done by typing:

~ cd Desktop

and pressing Enter. The “cd” stands for “change directory,” after which we tell the terminal where to go.

Once in the Desktop folder, we can check the dependencies of the Linux installer by typing:

~ ldd ./“X-Plane 10 Installer Linux”

and pressing Enter. The libraries listed there can be searched for either in the distribution’s package installer or on Google. For the Linux distributions in this guide, we won’t go through this step because we already know which packages are needed. You can get each of the packages by typing:

            ~ sudo apt-get install [package]

Running the installer

Once the proper libraries are installed, running the installer is as simple as opening a terminal, navigating to the desktop (via “cd Desktop” in most cases), and executing the file by typing:

~ ./“X-Plane 10 Installer Linux”

and pressing Enter.

From there, the installer itself can walk the user through the setup. By default, the installation will be placed in the directory /home/[user name]/X-Plane 10.”

6) Restart if prompted (for dependencies).

7) Run X-Plane for the first time (yay!). Do this:

~ cd "X-Plane 10"
~ ./X-Plane-x86_64

sudo helped here because of a filesystem issue that was specific to my instance…you may need to write a rule for the optical drive if you’re not root and don’t want to be lazy like me. You need to make sure DVD 1 is in the optical drive while running the simulator. 

8) Performance tune. Believe it or not, I’m running the simulator with NO graphics or video cards. I’m only using the on-board graphics. It runs excellent. However, if your install isn’t running epic, you can try a few things:

Follow the performance tuning steps here: http://wiki.x-plane.com/Setting_Up_X-Plane_for_Best_Performance

Leave me a comment or message if you run into issues or want to share additional tips. The forums are an excellent resource, as you can see by the comments…this is some of the best supported commercial software I’ve encountered.

-A

IIS/PHP/SQL Server 2012 Troubleshooting

I miss LAMP stack…

I like php with mysql on linux…actually one of my favorite things. Trying to recreate an app from my debian box to one of my windows machines and found that the recommended configuration is php with sql server (color me shocked)….which is fine. SQL Server is pretty locked down when it comes to security settings – rightfully so, you don’t want your typical user to unknowingly make their machine into a server. Took a few minutes of playing around with it, but this is how you fix the various errors you’ll encounter when trying to write php on your windows box with sql server 2012 and iis:

1) PHP isn’t installed. Grab PHP (http://windows.php.net/download/) and use the handy new PHP installer for Windows with IIS (http://php.iis.net/). If you have one of the more modern Windows OS’s you have IIS already, but you may need to snag iis express. In IIS, you can register a new PHP version – you should see PHP manager on IIS once you run the 2 downloads above. If you can’t get IIS to play nice, leave me a comment and I’ll help you through it. Or we can move on with our lives and install apache…
2) SQL Server Authentication isn’t configured right. Open up SQL Server. Right click your server name and go to properties. Under Security on the left, you should see Mixed Mode authentication. Make sure that’s ticked. Under connections, tick Allow Remote Connections. I’m assuming you’re trying to remote in eventually, so you’ll need a new user on SQL server that can login with sql server authentication. Sometimes the wizards and menus are wonky, so try opening a new query and following these directions: http://stackoverflow.com/questions/1601186/sql-server-script-to-create-a-new-user. After that, you can use that user in the code in step 4.
3) SQL Server isn’t letting you connect. Open up SQL Server Configuration Manager. You should see SQL Server Network Configuration. When you click it you will see your named instances. Click into each one. There are two fields, protocol name and status. Try enabling Shared Memory, Named Pipes, and TCP/IP. These three should let you call in from a remote host using SQL server authentication.
4) Your code is wrong. Just follow this…should work nicely and help you further troubleshoot: http://www.php.net/manual/en/function.sqlsrv-connect.php

Hope that helps…this should solve “Login failed for user” in your php app.

IIS 8, debugging MVC and running WCF service

I had a fun time yesterday with trying to run a service and debug an mvc app…

1) Tried to actually deploy the service to IIS – that worked, but broke visual studio 12’s IIS instance somehow. Not sure whether it was the Azure emulator or VS that actually had a broken config, but whatever.

2) Uninstalled IIS – that didn’t work because I didn’t actually delete everything from wwwroot. Deleted everything from wwwroot, then reinstalled IIS express. Now IIS works again. 

3) Finally figured out that you can’t deploy the service and run IIS from VS at the same time. Simple solution to all my problems? Open two instances of visual studio, one for the service, one for the Azure/MVC app. For the service instance, hit ctrl+f5 to run without debugging. For the mvc instance, run with or without debugging. 

 

Success…n00b move though, should have thought of the solution more quickly than I did. 

Mysql error 13…!@#$!@#$!@#$ (Ubuntu 13.x)

New ubuntu 13 install, yay. Mysql errors, boo. Tried reinstalling, thought it could be a lamp bulk install issue on the latest release (used the tasksel method). Figured out a few tricks to fix this error I was getting when I created a database:

mysql> create database db;
ERROR 13 (HY000): Can’t get stat of ‘./db’ (Errcode: 13)

!@#$!@$!@$

Error 13 means a permission issue usually…not a problem…let’s login as root…my fault, that was a n00b move (though ashley is the mask for my root right now):

ashley@c0dem0nkey:~$ mysql -u root -p

still ERROR 13!!! !@#$!@#$!@

Last thing…check if there’s permission to write to the mysql directory in var (where you store the database text files). AH HA!!!
do this:

~ ls -la /var/lib/mysql
ls: cannot open directory /var/lib/mysql: Permission denied

k so need everyone able to write to that directory. Use chmod for that…I took the lazy way out and gave everyone basically admin where the X’s are (not recommended):

~ sudo chmod XXX /var/lib/mysql

XXX is where you put the numeric code. 777 gives admin…DO NOT DO 777 unless you understand the ramifications..as in…7 lets you execute! 444 lets everyone read…which is probably enough. Check out this man page for more: http://ss64.com/bash/chmod.html.

Now it all works. Haven’t hit the server from another machine yet just to check port crap, but at least I can locally create and use db’s. Win.

SharePoint…stuff

Just a quickie on how to use external libraries in sharepoint for custom javascript. Also has a little on sp.js and how to deal with timing issues while loading…The html code was made pressable using my jsfiddle here: http://jsfiddle.net/gDqZ7/2/



   <style type="text/css">


 //CSS HERE!!!

    </style>

<div>
MARKUP GOES HERE!!!
</div>

<script src="_layouts/15/sp.js"></script>

<script src="_layouts/15/sp.runtime.js"></script>

<script>    
 $(window).load(function() {

// call your method onload here…ViewItem is a method that 
// takes no parameters and waits for sp.js to load…
//ExecuteOrDelayUntilScriptLoaded(ViewItem, "sp.js");

      
     });

//this creates a modal dialogue for a link with a title
function navLink(theLink, theFolder)
{


var options = SP.UI.$create_DialogOptions();

options.title = theFolder;
options.width = 600;
options.height= 600;
options.url = theLink;
SP.UI.ModalDialog.showModalDialog(options);
}

//this goes to a folder in a modal dialogue
function LaunchAllDocs()
{

var options = SP.UI.$create_DialogOptions();

options.title = "All Documents";
options.width = 600;
options.height= 600;
options.url = "ohhai.aspx";
SP.UI.ModalDialog.showModalDialog(options);
}


</script>

<!--[if IE]>
//custom styles for IE if you need them
    </style>
<![endif]-->

<script type='text/javascript'>
 
//minified libraries go here…I know it’s irritating but the sp instance I had
//wouldn’t reference the files I needed on the server and I can’t exactly cdn 
//now can I?

</script>







I made a toy. It allows you to post html code in wordpress code tags.

I got annoyed with posting ugly code that can’t use code tags. So I wrote some really simple javascript that replaces the characters that don’t work with wordpress. Play with my jsfiddle here…

http://jsfiddle.net/gDqZ7/2/

I got the characters to replace here:
http://codex.wordpress.org/Writing_Code_in_Your_Posts



//I typed these characters and now they work in here. cool.
[]&// 

<html>
</html>

 

Rich Content without JavaScript (Not elegant but it works)

Oh hai! I’ve been MIA…and that sucks. But I’m back. Recently had a challenge to do some rich content with mouseovers on the Jive framework on an internal site. For those not familiar with Jive, we’re using it as an internal social media/collaboration/KM tool. It has a set of “web part” type things (a la SharePoint) that you allegedly can use to create rich content on a group page. There’s an HTML part and a collapsible HTML part…they both SHOULD be able to handle javascript but alas…it appears the feature has been turned off by our security admin. So someone asked for a CSS “hack” for this…this is what I came up with after a bit of Googling and remembering some basic html/css that I’ve had to do before.

“Why aren’t you using classes more here?” I wish I could, but the html editor kept wiping them out. Outside of Jive, you should use CSS classes to accomplish something similar to this code. However, I’m lazy and wanted to copy/paste most of what I had already written 😛


Original Code

Here’s the JSFiddle: http://jsfiddle.net/PwGR3/


<div id="a" style="position:absolute;left:0px;height:95px; 
width:95px;background-color:darkred;text-align:center;">
<a style="color:white;font-size:24px;text-align:center;" href="#"><br />Content A</a>

</div>
<div id="b" style="position:absolute;left:100px;height:95px; 
width:95px;background-color:darkred;text-align:center;">
<a style="color:white;font-size:24px;text-align:center;" href="#"><br />Content B</a>

</div>
<div id="c" style="position:absolute;left:200px;height:95px; 
width:95px;background-color:darkred;text-align:center;">
<a style="color:white;font-size:24px;text-align:center;" href="#"><br />Content C</a>

</div>
<div id="d" style="position:absolute;left:300px;height:95px; 
width:95px;background-color:darkred;text-align:center;">
<a style="color:white;font-size:24px;text-align:center;" href="#"><br />Content D</a>

</div>
<div id="e" style="position:absolute;left:400px;height:95px; 
width:95px;background-color:darkred;text-align:center;">
<a style="color:white;font-size:24px;text-align:center;" href="#"><br /> Content E</a>

</div>
<div id="f" style="position:absolute;left:500px;height:95px; 
width:95px;background-color:darkred;text-align:center;">
<a style="color:white;font-size:24px;text-align:center;" href="#"><br /> Content F</a>

</div>
<br/>
<div style="height:85px;width:600px;"></div>
<div id="result"></div>
<div class="TextDiv" id="AText">
    <h1>A div</h1>
</div>
<div class="TextDiv" id="BText">
    <h1>B div</h1>
</div>
<div class="TextDiv" id="CText">
    <h1>C div</h1>
</div>
<div class="TextDiv" id="DText">
    <h1>D div</h1>
</div>
<div class="TextDiv" id="EText">
    <h1>Placeholder example</h1>
</div>
<div id="result2" style="background-color:gray;height:400px;width:600px;"></div>

Admittedly Bad CSS



<style type="text/css"> #a:hover ~ #result {

    height:400px;

    width:600px;

    background-image: url('something.png');

}

#b:hover ~ #result {

    height:400px;

    width:600px;

    background-color:blue;

}

#c:hover ~ #result {

    height:400px;

    width:600px;

    background-color:purple;

}

#d:hover ~ #result {

    height:400px;

    width:600px;

    background-image: url('someotherurl.png');

}

#e:hover ~ #result {

    height:400px;

    width:600px;

    background-image: url('something.png');

}

#f:hover ~ #result {

    height:400px;

    width:600px;

    background-image: url('ohhai.png');

}

#a:hover ~ #result2 {

    display:none;

}

#b:hover ~ #result2 {

    display:none;

}

#c:hover ~ #result2 {

    display:none;

}

#d:hover ~ #result2 {

    display:none;

}

#e:hover ~ #result2 {

    display:none;

}

#f:hover ~ #result2 {

    display:none;

}

#e:hover ~ .TextDiv {

    display:none;

}

#e:hover ~ #EText {

    display:block !important;

    text-shadow: -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000;

}

#f:hover ~ .TextDiv {

    display:none;

}

#f:hover ~ #FText {

    display:block !important;

}

#a:hover ~ .TextDiv {

    display:none;

}

#a:hover ~ #AText {

    display:block !important;

    text-shadow: -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000;

}

#b:hover ~ .TextDiv {

    display:none;

}

#b:hover ~ #BText {

    display:block !important;

    text-shadow: -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000;

}

#c:hover ~ .TextDiv {

    display:none;

}

#c:hover ~ #CText {

    display:block !important;

    text-shadow: -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000;

}

#d:hover ~ .TextDiv {

    display:none;

}

#d:hover ~ #DText {

    display:block !important;

    text-shadow: -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000;

}

.TextDiv {

    opacity:0.7;

}

.TextDiv H1 {

    position:absolute;

    top:500px;

    left:200px;

    color:white;

    font-size:20pt;

    /*display:none;*/

}

</style>

Javascript onload headaches

I’ve got a client that uses only firefox and IE. Lucky for me, IE is non standards compliant at the most inconvenient times. Where I would have normally just done:

window.onload = myJavascriptMethod();

IE won’t do it!

(Huge surprise)

I also didn’t realize this error until I posted to production. Anywho…back to the post. I found a GREAT fix for this here: http://dean.edwards.name/weblog/2005/09/busted/

Which works well.

Here’s what you do:

1) Make a separate file called iescript.js in your project. You literally only need to put this in the file:

init();

Nothing else.

2. Put this before your javascript:

<!–[if IE]><script defer src=”iescript.js”></script><![endif]–>

3) Now put in your script tags (since I wrestle with .net, I usually do this with document.ready):

<script type=”text/javascript”>
    $(document).ready(function () {
        //window.onload(allfunctions());
        if (document.addEventListener) {
//            document.addEventListener(“DOMContentLoaded”, init, false);
//        }
//        else {
            window.onload = init();
        }

    });
     function init() {
         // quit if this function has already been called
         if (arguments.callee.done) return;

         // flag this function so we don’t do the same thing twice
         arguments.callee.done = true;

         // do stuff
       
     }
    

</script>

 

So you’ll see above if you click my link to Dean Edwards’ blog, I changed some of their code. This is a combination of .net and new mozilla release issues. You don’t really need to do this:

document.addEventListener(“DOMContentLoaded”, init, false);

Instead, just check for whether you CAN add the event (you can only do it in firefox):

if (document.addEventListener) {

            window.onload = init();
        }

And if you remember, init() is where I have all the javascript functions I want to call.

 

Again, a lot of this post features code from Dean Edwards and isn’t mine, but I did want to post my edits/comments/kudos here so maybe someone else can benefit using it with an asp.net app.

 

Cheers!

 

-Monkey

Excel exports with C# NPOI – Doing sweet stuff with images

Ever wonder how to put an image on your excel export? Here’s how:

 

//map the path to the img folder
                string imagesPath = System.IO.Path.Combine(Server.MapPath(“~”), “img”);
                //grab the image file
                imagesPath = System.IO.Path.Combine(imagesPath, “AwesomeImage.png”);
                //create an image from the path
                System.Drawing.Image image = System.Drawing.Image.FromFile(imagesPath);
                MemoryStream ms = new MemoryStream();
                //pull the memory stream from the image (I need this for the byte array later)
                image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                //the drawing patriarch will hold the anchor and the master information
                HSSFPatriarch patriarch = sheet1.CreateDrawingPatriarch();
                //store the coordinates of which cell and where in the cell the image goes
                int intx1 = 3;
                int inty1 = 10;
                int intx2 = 4;
                int inty2 = 11;

            
                HSSFClientAnchor anchor = new HSSFClientAnchor(20, 0, 40, 20, intx1, inty1, intx2, inty2);
                //types are 0, 2, and 3. 0 resizes within the cell, 2 doesn’t
                anchor.AnchorType = 2;
                //add the byte array and encode it for the excel file
                int index = hssfworkbook.AddPicture(ms.ToArray(), HSSFPicture.PICTURE_TYPE_PNG);
                HSSFPicture signaturePicture = patriarch.CreatePicture(anchor, index);

 

Few notes: 1) I’m using a png image, you have to change the picture type if you’re doing a different file type

2) My image is in the img folder of my project

3) This is grossly over-simplified and is meant to go inside of another method.

4) Call this after you’ve instantiated your workbook and your worksheet (duh!)