linux 安装nginx

从源代码编译 Nginx
下载地址http://nginx.org/ 下载源码包


安装前提 
在安装nginx前,需要确保系统安装了g++、gcc、openssl-devel、pcre-devel和zlib-devel软件。安装必须软件: 
shell> yum -y install gcc-c++ zlib zlib-devel openssl openssl-devel pcre pcre-devel
检查系统安装的Nginx: 
shell> find -name nginx
./nginx
./nginx/sbin/nginx
./nginx-1.2.6/objs/nginx 
卸载原有的Nginx
shell> yum -y remove nginx 
安装 
将安装包文件上传到/opt/local中执行以下操作: 
shell> cd /opt/local
shell> tar -zxvf nginx-1.2.6.tar.gz
shell> mv nginx-1.2.6 nginx
shell> cd /opt/local/nginx
shell> ./configure --prefix=/opt/local/nginx(安装目录) --with-http_ssl_module
shell> make && make install
配置 
#修改防火墙配置: 
shell> vim /etc/sysconfig/iptables
#添加配置项 
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
#重启防火墙 
shell> service iptables restart 
启动 
#方法1
shell> /opt/local/nginx/sbin/nginx -c /opt/local/nginx/conf/nginx.conf
注:启动时报错nginx: [error] open() "/opt/local/nginx/logs/nginx.pid" failed (2: No such file or directory),则一定要用这种方式启动
#方法2
shell> /opt/local/nginx/sbin/nginx
停止 
#查询nginx主进程号 
ps -ef|grep nginx
#停止进程 
kill -QUIT 主进程号 
#快速停止 
kill -TERM 主进程号 
#强制停止 
pkill -9 nginx
重启 
shell> /opt/local/nginx/sbin/nginx -s reload
测试 
#测试端口 
netstat –na|grep 80

你可能感兴趣的:(linux,nginx)