ubuntu 從官方來源安裝nginx
cd ~ wget http://nginx.org/keys/nginx_signing.key sudo apt-key add nginx_signing.key sudo nano /etc/apt/sources.list # 添加以下两句 deb http://nginx.org/packages/ubuntu/ precise nginx deb-src http://nginx.org/packages/ubuntu/ precise nginx sudo apt-get update sudo apt-get install nginx
ubuntu 從ppa來源安裝nginx :
##
sudo add-apt-repository ppa:nginx/stable sudo apt-get update sudo apt-get install nginx
ubuntu 從常規來源安裝nginx :
sudo apt-get install nginx
編譯安裝nginx
wget http://nginx.org/packages/mainline/ubuntu/pool/nginx/n/nginx/nginx_1.5.7-1~precise_i386.deb wget http://nginx.org/download/nginx-1.5.7.tar.gz tar xzf nginx-1.5.7.tar.gz cd nginx-1.5.7
sudo mkdir /png sudo chown eechen:eechen /png
sudo addgroup png --system sudo adduser png --system --disabled-login --ingroup png --no-create-home --home /nonexistent --gecos "png user" --shell /bin/false
./configure \
--prefix=/png/nginx/1.5.7 \ --sbin-path=/png/nginx/1.5.7/sbin/nginx \ --conf-path=/png/nginx/1.5.7/conf/nginx.conf \ --error-log-path=/png/nginx/1.5.7/var/log/error.log \ --http-log-path=/png/nginx/1.5.7/var/log/access.log \ --pid-path=/png/nginx/1.5.7/var/run/nginx.pid \ --lock-path=/png/nginx/1.5.7/var/run/nginx.lock \ --http-client-body-temp-path=/png/nginx/1.5.7/var/cache/client_temp \ --http-proxy-temp-path=/png/nginx/1.5.7/var/cache/proxy_temp \ --http-fastcgi-temp-path=/png/nginx/1.5.7/var/cache/fastcgi_temp \ --http-uwsgi-temp-path=/png/nginx/1.5.7/var/cache/uwsgi_temp \ --http-scgi-temp-path=/png/nginx/1.5.7/var/cache/scgi_temp \ --user=png \ --group=png \ --with-http_ssl_module \ --with-http_realip_module \ --with-http_addition_module \ --with-http_sub_module \ --with-http_dav_module \ --with-http_flv_module \ --with-http_mp4_module \ --with-http_gunzip_module \ --with-http_gzip_static_module \ --with-http_random_index_module \ --with-http_secure_link_module \ --with-http_stub_status_module \ --with-mail \ --with-mail_ssl_module \ --with-file-aio \ --with-ipv6
sudo apt-get -y install \
build-essential \ autoconf \ libtool \ libxml2 \ libxml2-dev \ openssl \ libcurl4-openssl-dev \ libbz2-1.0 \ libbz2-dev \ libjpeg-dev \ libpng12-dev \ libfreetype6 \ libfreetype6-dev \ libldap-2.4-2 \ libldap2-dev \ libmcrypt4 \ libmcrypt-dev \ libmysqlclient-dev \ libxslt1.1 \ libxslt1-dev \ libxt-dev \ libpcre3-dev
好了,configure成功後就可以編譯安裝了:
time make && make install
編譯好後可以看看這個傢伙的個頭:
du -sh /png/nginx/1.5.7/sbin/nginx
5.5m /png/nginx/1.5.7/sbin/nginx
環境簡單配置總結
減少nginx編譯後的檔案大小:編輯原始檔nginx-1.5. 7/auto/cc/gcc 去除debug訊息(註解掉即可):
# debug # cflags="$cflags -g"
另外configure時去掉一些不需要的模組,編譯後的可執行檔會更小.
當然,我需要一個服務腳本用來管理nginx,這時同樣可以藉助官方deb包裡提供的服務腳本etc/init.d/nginx.
我把它放到/png/nginx/1.5.7/nginx,對開頭定義的幾個值(13到19行)進行稍加修改:
path=/sbin:/usr/sbin:/bin:/usr/bin desc=nginx name=nginx conffile=/etc/nginx/nginx.conf daemon=/usr/sbin/nginx pidfile=/var/run/$name.pid scriptname=/etc/init.d/$name 改为 path=/sbin:/usr/sbin:/bin:/usr/bin desc=nginx name=nginx conffile=/png/nginx/1.5.7/conf/nginx.conf daemon=/png/nginx/1.5.7/sbin/nginx pidfile=/png/nginx/1.5.7/var/run/$name.pid scriptname=/png/nginx/1.5.7/$name
mkdir /png/nginx/1.5.7/var/cache
sudo /png/nginx/1.5.7/nginx start
curl -i `hostname`
sudo netstat -antp|grep nginx
htop按f4過濾nginx
top -b -n1|head -n7 && top -b -n1|grep nginx
ps aux|head -n1 && ps aux|grep nginx
cat /proc/25047/status|grep threads
threads: 1
sudo ln -s /png/nginx/1.5.7/nginx /etc/init.d/png-nginx sudo update-rc.d png-nginx defaults #开机自启动 sudo update-rc.d -f png-nginx remove # 以后不想开机自启动可以这样禁止 sudo service png-nginx reload #这样就可以用service来管理nginx服务了,比如重载配置
以上是Ubuntu上安裝Nginx伺服器程式及簡單環境配置的方法的詳細內容。更多資訊請關注PHP中文網其他相關文章!