從 http://nginx.org/download/nginx-1.9.15.tar.gz 下載nginx包(或者wget http://nginx.org/download/nginx-1.9.15.tar.gz直接在Linux上用命令下載)html
解壓並轉到目錄下nginx
tar -zxvf nginx-1.9.15.tar.gz cd nginx-1.9.15
設置一下配置信息 ./configure --prefix=/usr/local/nginx
,或者不執行此步,直接默認配置c++
編譯安裝ubuntu
make make install
make的過程是把各類語言寫的源碼文件,變成可執行文件和各類庫文件;
make install是把這些編譯出來的可執行文件和庫文件複製到合適的地方。瀏覽器
./configure --prefix=/usr/local/nginx
的時,出現錯誤:/configure: error: the HTTP rewrite module requires the PCRE library.
解決方法:安裝pcreui
yum -y install pcre pcre-devel
-y 是跳過全部須要手動確認的環節code
./configure: error: the HTTP cache module requires md5 functions from OpenSSL library. You can either disable the module by using --without-http-cache option, or install the OpenSSL library into the system, or build the OpenSSL library statically from the source with nginx by using --with-http_ssl_module --with-openssl=<path> options.
解決方法:安裝opensslhtm
yum -y install openssl openssl-devel
./configure: error: C compiler cc is not found
解決方法:安裝gcc-c++ip
yum -y install gcc-c++ autoconf automake
autoconf是自動配置,automake是自動編譯md5
./configure: error: the HTTP gzip module requires the zlib library. You can either disable the module by using –without-http_gzip_module option, or install the zlib library into the system, or build the zlib library statically from the source with nginx by using –with-zlib=<path> option.
解決方法:安裝zlib
yum install -y zlib-devel
fastcgi.conf koi-win nginx.conf.default fastcgi.conf.default logs scgi_params fastcgi_params mime.types scgi_params.default fastcgi_params.default mime.types.default uwsgi_params html nginx uwsgi_params.default koi-utf nginx.conf win-utf
確保系統的 80 端口沒被其餘程序佔用,運行/usr/local/nginx/nginx 命令來啓動 Nginx,
netstat -ano|grep 80
若是查不到結果後執行,有結果則忽略此步驟(ubuntu下必須用sudo啓動,否則只能在前臺運行)
sudo /usr/local/nginx/nginx
打開瀏覽器訪問此機器的 IP,若是瀏覽器出現 Welcome to nginx! 則表示 Nginx 已經安裝並運行成功。