.bz2 解压命令 $ tar jxf file-namephp
.gz 解压命令 $ tar zxf file-namehtml
$ yum install -y gcc gcc-c++ make cmake autoconf libtool \ libtool-ltdl-devel pcre pcre-devel gd-devel freetype-devel \ libxml2-devel libjpeg-devel libpng-devel openssl-devel \ curl-devel patch libmcrypt-devel libmhash-devel ncurses-devel \ sudo bzip2 bzip2-devel bison perl-devel perl-ExtUtils-Embed \ libcurl-devel libjpeg-devel libpng-devel freetype-devel \ t1lib-devel libicu-devel mhash libmcrypt libmcrypt libiconv \ libxslt-devel openldap-devel
添加用户组nginx
$ groupadd nginx $ useradd -g nginx -s /sbin/nologin nginx
新建日志目录c++
$ mkdir -p /var/nginx/log
编译安装Nginxvim
编译参数app
$ ./configure \ --user=nginx \ --group=nginx \ --prefix=/usr/local/nginx \ --sbin-path=/usr/sbin/nginx \ --conf-path=/usr/local/etc/nginx/nginx.conf \ --error-log-path=/var/nginx/log/nginx/error.log \ --http-log-path=/var/nginx/log/nginx/access.log \ --pid-path=/var/nginx/log/run/nginx.pid \ --lock-path=/var/nginx/log/lock/subsys/nginx \ --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_gzip_static_module \ --with-http_stub_status_module \ --with-http_perl_module \ --with-mail \ --with-mail_ssl_module > out
安装curl
$ make $ make install
注意事项ui
1.若是碰到url
./configure: error: the HTTP rewrite module requires the PCRE library.,请安装pcre-devel: $ yum -y install pcre-devel
2.若是使用—with-http_sub_module参数编译出错的话,加参数—with-openssl=/download/openssl-1.0.1c, 这里指定的openssl目录是源码包解压出来的目录而不是openssl的安装目录。日志
配置文件
新建虚拟主机配置文件
$ vim /usr/local/etc/nginx/vhost.conf
加入
server { listen 80; server_name foo.com; root /www/foo; index index.html index.htm index.php; location / { try_files $uri $uri/ /index.php; } location ~ \.php$ { try_files $uri = 404; include fastcgi.conf; fastcgi_pass 127.0.0.1:9000; } }
在ningx.conf里引入虚拟主机配置文件
$ vim /usr/local/etc/nginx/nginx.conf
修改以下
http { include mime.types; include vhosts.conf; // 引入虚拟主机配置文件 default_type application/octet-stream;
Nginx命令
启动
$ nginx
平滑重启
$ nginx -s reload
中止
$ nginx -s stop