導讀 | Nginx是一款開放源代碼的高性能HTTP服務器和反向代理服務器,同時支持IMAP/POP3代理服務,是一款自由的軟件,同時也是運維工程師必會的一種服務器,下面我就簡單的說一下Nginx服務器的安裝和文件解析。 |
簡單安裝
本教程一Centos 6.3爲例講解,軟件包可以在官方網站下載,編譯安裝之前,我們需要使用YUM提前將所需的軟件依賴包安裝完成。 安裝命令如下:
[root@centos6 ~]# wget http://nginx.org/download/nginx-1.4.0.tar.gz [root@centos6 ~]# tar -xzf nginx-1.4.0.tar.gz -C /usr/src [root@centos6 ~]# yum -y install gcc pcre pcre-devel openssl \ >openssl-devel gd gd-devel perl perl-ExtUtils-Embed [root@centos6 ~]# cd /usr/src/nginx-1.4.0/ [root@centos6 nginx-1.4.0]# ./configure --prefix=/usr/local/nginx \ >--with-ipv6 \ >--with-http_ssl_module \ >--with-http_realip_module \ >--with-http_addition_module \ >--with-http_dav_module \ >--with-http_flv_module \ >--with-http_mp4_module \ >--with-http_gzip_static_module \ >--with-http_perl_module \ >--with-mail \ >--with_main_ssl_module [root@centos6 nginx-1.4.0]# make && make install
Nginx Web服務器軟件安裝完成後,程序主目錄位於/usr/local/nginx/,該目錄下的內容分別爲cong、html、logs、sbin。下面是Nginx常用的進程管理指令:
[root@centos6 ~]# /usr/local/nginx/sbin/nginx #啓動主程序 [root@centos6 ~]# /usr/local/nginx/sbin/nginx -c \ #指定配置文件啓動主程序 [root@centos6 ~]# /usr/local/nginx/sbin/nginx -s stop #關閉主程序 [root@centos6 ~]# /usr/local/nginx/sbin/nginx -s reload #重新加載設置
配置文件解析
Nginx默認的配置文件爲/usr/local/nginx/conf/nginx.conf,配置文件包括全局、event、http、server設置,event主要用來定義Nginx工作模式,http提供Web功能,server用來設置虛擬主機,server必須位於http內部,一個配置文件中可以有多個server。