<pre name="code" class="sql">web服务器nginx和apache的对比分析
yum -y install gcc gcc-c++ gcc-g77 autoconf automake zlib* fiex* libxml* ncurses* libmcrypt*
./configure --user=nginx --group=nginx --prefix=/usr/local/nginx/ --with-http_stub_status_module --with-http_ssl_module</span>
配置nginx
./configure --prefix=/usr/local/nginx --with-http_stub_status_module
解释: --prefix 为安装路径,--with-为需要安装的模块,具体可以运行./configure --help 查看有效模块
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option
yum -y install *pcre*
make
make install
v-lhb-web01:/root/nginx-1.7.7# /usr/local/nginx/sbin/nginx
v-lhb-web01:/root/nginx-1.7.7#
v-lhb-web01:/root/nginx-1.7.7#
v-lhb-web01:/root/nginx-1.7.7# ps -ef | grep nginx
root 26705 1 0 17:19 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody 26706 26705 0 17:19 ? 00:00:00 nginx: worker process
root 26708 21330 0 17:19 pts/0 00:00:00 grep nginx
v-lhb-web01:/root/nginx-1.7.7#
启用:
/usr/sbin/nginx -c /etc/nginx/nginx.conf
1.demo:/etc/nginx# /usr/local/nginx/sbin/nginx -c /etc/nginx/nginx.conf
nginx: [emerg] getpwnam("nginx") failed in /etc/nginx/nginx.conf:2
解决:创建nginx用户和组
jrhwpt01:/etc# id nginx
uid=411(nginx) gid=411(nginx) groups=411(nginx)
front-end:/root/nginx-1.7.7# useradd -m -g nginx -s /sbin/nologin nginx
2.demo:/etc/nginx# /usr/local/nginx/sbin/nginx -c /etc/nginx/nginx.conf
nginx: [emerg] open() "/etc/nginx/mime.types" failed (2: No such file or directory) in /etc/nginx/nginx.conf:16
文件路径不对:
demo:/usr/local/nginx# cd conf/
demo:/usr/local/nginx/conf# ls
fastcgi.conf fastcgi_params koi-utf mime.types nginx.conf scgi_params uwsgi_params win-utf
fastcgi.conf.default fastcgi_params.default koi-win mime.types.default nginx.conf.default scgi_params.default uwsgi_params.default
demo:/usr/local/nginx/conf# cp -r * /etc/nginx/
cp: overwrite `/etc/nginx/nginx.conf'? y
demo:/etc/nginx# /usr/local/nginx/sbin/nginx -c /etc/nginx/nginx.conf
demo:/etc/nginx#
启动正常
demo:/etc/nginx# /usr/local/nginx/sbin/nginx -c /etc/nginx/nginx.conf
demo:/etc/nginx# ps -ef | grep nginx
root 5213 1 0 15:54 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /etc/nginx/nginx.conf
nginx 5214 5213 0 15:54 ? 00:00:00 nginx: worker process
root 5216 1706 0 15:55 pts/0 00:00:00 grep nginx
demo:/etc/nginx#
demo:/etc/nginx# netstat -nap | grep nginx
tcp 0 0 0.0.0.0:8001 0.0.0.0:* LISTEN 5213/nginx
unix 3 [ ] STREAM CONNECTED 19847 5213/nginx
unix 3 [ ] STREAM CONNECTED 19846 5213/nginx
http://192.168.32.172:8001/
访问报
403 Forbidden
--------------------------------------------------------------------------------
nginx/1.7.7
1.修改权限:
demo:/var/www# chmod -R 777 zjzc-web-frontEnd
http://192.168.32.172:8001/ --正常访问
demo:/var/www# ps -ef | grep nginx
root 5280 1 0 16:01 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /etc/nginx/nginx.conf
nginx 5281 5280 0 16:01 ? 00:00:00 nginx: worker process
root 5319 1706 0 16:06 pts/0 00:00:00 grep nginx