Mac利用jpegoptim 无损压缩jpg jpeg图片

先用macport安装jpegoptim

port install jpegoptim

安装完毕后,即可使用,-h 查看参数用法

$ jpegoptim banner1.jpg
banner1.jpg 1024x683 24bit Exif Adobe  [OK] 156339 --> 155426 bytes (0.58%), optimized.

还可以在某个文件夹下批量进行压缩

find . -iname '*.jpg' -print0 | xargs -0 jpegoptim --max=90 --strip-all --preserve --totals --all-progressive

除此之外,还有一个专门压缩PNG的软件 optipng

Mac用port安装nginx

安装macport

到http://www.macports.org/install.php下载macports
安装nginx:运行

sudo port install nginx spawn-fcgi

安装php:运行

sudo port install php53 fcgi php53-cgi php53-mysql php53-curl php53-iconv php53-mcrypt

安装imagick: 运行

sudo port install php53-imagick

nginx配置
进入

cd /opt/local/etc/nginx

创建sites-avalaible和sites-enabled文件夹
参考附件的配置文件,编辑nginx.conf, fastcgi.conf, mime.types
参考附件的配置文件在sites-available中创建web配置文件

php 配置


 error_reporting = E_ALL & ~E_NOTICE
 display_errors = On
 date.timezone = Asia/Shanghai
 short_open_tag = On



开启自启动配置
将以下代码保存至/Library/LaunchDaemons/org.macports.nginx.plist

 <?xml version='1.0' encoding='UTF-8'?>
 <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
 "<span style="text-decoration: underline;">http://www.apple.com/DTDs/PropertyList-1.0.dtd</span>" >
 <plist version='1.0'>
 <dict>
 <key>Label</key><string>org.macports.nginx</string>
 <key>ProgramArguments</key>
 <array>
         <string>/opt/local/bin/daemondo</string>
         <string>--label=nginx</string>
         <string>--start-cmd</string>
         <string>/opt/local/sbin/nginx</string>
         <string>;</string>
         <string>--pid=fileauto</string>
         <string>--pidfile</string>
         <string>/opt/local/var/run/nginx/nginx.pid</string>
 </array>
 <key>Debug</key><false/>
 <key>Disabled</key><true/>
 <key>KeepAlive</key><true/>
 </dict>
 </plist>

将以下代码保存至/Library/LaunchDaemons/org.macports.phpfcgi.plist

 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "<span style="text-decoration: underline;">http://www.apple.com/DTDs/PropertyList-1.0.dtd</span>">
 <plist version="1.0">
 <dict>
   <key>Label</key><string>org.macports.phpfcgi</string>
   <key>Debug</key><false />
   <key>OnDemand</key><false />
   <key>RunAtLoad</key><false />
   <key>EnvironmentVariables</key>
   <dict>
     <key>PHP_FCGI_CHILDREN</key><string>2</string>
     <key>PHP_FCGI_MAX_REQUESTS</key><string>5000</string>
   </dict>
   <key>LaunchOnlyOnce</key><true />
   <key>ProgramArguments</key>
   <array>
     <string>/opt/local/bin/spawn-fcgi</string>
     <string>-C 2</string>
     <string>-p 9000</string>
     <string>-f /opt/local/bin/php-cgi53</string>
   </array>
 </dict>
 </plist>

运行

sudo launchctl load -w /Library/LaunchDaemons/org.macports.nginx.plist

运行

sudo launchctl load -w /Library/LaunchDaemons/org.macports.phpfcgi.plist

运行

sudo lsof -i:80

sudo lsof -i:9000

检查nginx和fastcgi是否分别正常监听80和9000端口
如果安装php扩展,安装后重启fastcgi即可

sudo killall php-cgi53
sudo php-cgi53 -b 127.0.0.1:9000  &

Mac port 安装 nginx php 环境

用port安装nginx
到http://www.macports.org/install.php下载macports
安装nginx:运行sudo port install nginx spawn-fcgi
安装php:运行sudo port install php53 fcgi php53-cgi php53-mysql php53-curl php53-iconv php53-mcrypt
安装imagick: 运行sudo port install php53-imagick

nginx配置
进入/opt/local/etc/nginx
创建sites-avalaible和sites-enabled文件夹
参考附件的配置文件,编辑nginx.conf, fastcgi.conf, mime.types
参考附件的配置文件在sites-available中创建www, game, bbs三个配置文件分别指向3个git代码库的根目录或webroot目录

php 配置
error_reporting = E_ALL & ~E_NOTICE
display_errors = On
date.timezone = Asia/Shanghai
short_open_tag = On

开启自启动配置

  1. 将以下代码保存至/Library/LaunchDaemons/org.macports.nginx.plist
    <?xml version='1.0' encoding='UTF-8'?>
    <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
    "http://www.apple.com/DTDs/PropertyList-1.0.dtd" >
    <plist version='1.0'>
    <dict>
    <key>Label</key><string>org.macports.nginx</string>
    <key>ProgramArguments</key>
    <array>
            <string>/opt/local/bin/daemondo</string>
            <string>--label=nginx</string>
            <string>--start-cmd</string>
            <string>/opt/local/sbin/nginx</string>
            <string>;</string>
            <string>--pid=fileauto</string>
            <string>--pidfile</string>
            <string>/opt/local/var/run/nginx/nginx.pid</string>
    </array>
    <key>Debug</key><false/>
    <key>Disabled</key><true/>
    <key>KeepAlive</key><true/>
    </dict>
    </plist>
  2. 将以下代码保存至/Library/LaunchDaemons/org.macports.phpfcgi.plist
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
      <key>Label</key><string>org.macports.phpfcgi</string>
      <key>Debug</key><false />
      <key>OnDemand</key><false />
      <key>RunAtLoad</key><false />
      <key>EnvironmentVariables</key>
      <dict>
        <key>PHP_FCGI_CHILDREN</key><string>2</string>
        <key>PHP_FCGI_MAX_REQUESTS</key><string>5000</string>
      </dict>
      <key>LaunchOnlyOnce</key><true />
      <key>ProgramArguments</key>
      <array>
        <string>/opt/local/bin/spawn-fcgi</string>
        <string>-C 2</string>
        <string>-p 9000</string>
        <string>-f /opt/local/bin/php-cgi53</string>
      </array>
    </dict>
    </plist>
  3. 运行sudo launchctl load -w /Library/LaunchDaemons/org.macports.nginx.plist
  4. 运行sudo launchctl load -w /Library/LaunchDaemons/org.macports.phpfcgi.plist
  5. 运行sudo lsof -i:80和sudo lsof -i:9000检查nginx和fastcgi是否分别正常监听80和9000端口