Passing custom server headers to php running under Nginx

Nginx doesn’t seem to pass any additional custom header to $_SERVER variable. To make this happen you need to:

1. First the custom http header sending out (from your REST client) need to use dash instead of underscore, for example “HTTP-X-REST-USERNAME”.

2. On the server side, in your fastcgi_params file (/etc/nginx/fastcgi_params) add this:

fastcgi_param   HTTP_X_REST_USERNAME    $http_x_rest_username;

3. Restart server you will see $_SERVER[‘HTTP_X_REST_USERNAME’] inside php land.

Nginx VHost for WordPress

server {
        listen 80;
        index index.php;

        root /mnt/projects/wordpress;
        server_name wordpress.server.local;

        location / {
                try_files $uri $uri/ /index.php?q=$uri&$args;
        }

        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include /etc/nginx/fastcgi_params;
        }

        location = /(favicon.ico|robots.txt)$ {
                log_not_found off;
                access_log off;
        }

        location ~ /\. {
                deny all;
                access_log off;
                log_not_found off;
        }
}

Nginx VHost

The example is for YiiFramework project

server {
        listen 80;
        index index.php;

        root /mnt/projects/yiihaw;
        server_name yiihaw.server.local;

        location / {
                try_files $uri $uri/ /index.php?$args;
        }

        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include /etc/nginx/fastcgi_params;
        }

        location = /(favicon.ico|robots.txt)$ {
                log_not_found off;
                access_log off;
        }       

        location ~ /((protected|framework|nbproject)|\.) {
                deny all;
                access_log off;
                log_not_found off;
        }
}

Use Weather HD as your screen saver

Weather HD is a very pretty Weather forecast app on both OS X and iOS. One thing it’s missing is to have the option to active as screen saver.

But here we have a workaround to make it happen.

First download the attached file which contains 3 things:
– The ScriptSaver.saver which is a Mac Screen Saver profile that allows us to hook screen saver events to Apple Script
– LaunchWeatherHD.scpt Apple Script to launch Weather HD, assuming Weather HD is in /Applications
– CloseWeatherHD.scpt Apple Script to close Weather HD

Now first thing is unzip the file, and copy those 3 files into the Library/Screen Savers/ directory in your home directory. You probably need to un-hide the Library directory by:

chflags nohidden ~/Library

Once this is done, go to “System Preferences” > “Desktop & Screen Saver” > “Screen Saver”, you should see a new Screen Saver appears on the list, (usually at the bottom), called “ScriptSaver”, select it, and click “Screen Saver Options”, which will bring up this screen:


(Screenshot taken in Mountain Lion, if you are using other version of OS X, it will be slightly different but it doesn’t matter)

Now you only need to change 2 things here: the “Activation Script” and “Deactivation Script” setting, mine are:
Activation Script: /Users/vincent/Library/Screen Savers/LaunchWeatherHD.scpt
Deactivation Script: /Users/vincent/Library/Screen Savers/LaunchWeatherHD.scpt
(change /Users/vincent to your home directory path, ScriptSaver doesn’t support relative path here :()

Now click “OK” everything is done. When this Screen Saver gets called it will activate the Weather HD and close it when you exit Screen Saver.

Troubleshoot:

First make sure Screen Saver actually starts before your Display goes to sleep (settings in “Energy Savers”). Also make sure “Require password after sleep or screen saver begins” in “Security & Privacy” is turned off.
After a default install of Weather HD it sometimes asks you to rate it which stops itself from launching automatically, just go to AppStore and rate it…

And yes this works from Leopard to Mountain Lion, at least.

Some Mac OS X Config

defaults write com.apple.desktopservices DSDontWriteNetworkStores true
defaults write com.apple.LaunchServices LSQuarantine -bool NO
defaults write com.apple.LaunchServices LSQuarantine -bool false
defaults write NSGlobalDomain NSTextShowsControlCharacters -bool true
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad Clicking -bool true
defaults -currentHost write NSGlobalDomain com.apple.mouse.tapBehavior -int 1
defaults write NSGlobalDomain com.apple.mouse.tapBehavior -int 1
defaults write com.apple.finder QLEnableTextSelection -bool true
defaults write com.apple.dock "dashboard-in-overlay" -bool true
defaults write com.apple.dashboard devmode -bool true
defaults write com.apple.terminal StringEncodings -array 4

mkdir Library/KeyBindings
vim ~/Library/KeyBindings/DefaultKeyBinding.dict