您的位置:首页 > 运维架构 > Nginx

nginx 安装 卸载 开启ssl

2016-11-10 18:06 387 查看
卸载

如果卸载ngixn 直接找到nginx安装目录   直接删除即可。

安装

1、准备工作
选首先安装这几个软件:GCC,PCRE(Perl Compatible Regular Expression),zlib,OpenSSL。
Nginx是C写的,需要用GCC编译;Nginx的Rewrite和HTTP模块会用到PCRE;Nginx中的Gzip用到zlib;
用命令“# gcc”,查看gcc是否安装;如果出现“gcc: no input files”信息,说明已经安装好了。
否则,就需要用命令“# yum install gcc”,进行安装了!一路可能需要多次输入y,进行确认。
安装好后,可以再用命令“#gcc”测试,或者用命令“# gcc -v”查看其版本号。
同样方法,用如下命令安装PCRE,zlib,OpenSSL(其中devel,是develop开发包的意思):

[plain] view
plain copy

 





# yum install -y pcre pcre-devel  

# yum install -y zlib zlib-devel  

# yum install -y openssl openssl-devel  

2、下载并安装
创建目录(nginx-src)并进去;然后,从官方地址(http://nginx.org/)下载,解压,配置,编译,安装:

[plain] view
plain copy

 





# mkdir nginx-src && cd nginx-src  

# wget http://nginx.org/download/nginx-1.7.3.tar.gz  

# tar xzf nginx-1.7.3.tar.gz   

# cd nginx-1.7.3  

# ./configure   (  ./configure
 --with-http_ssl_module  
nginx增加ssl支持 )

# make  

# make install  

# whereis nginx  

nginx: /usr/local/nginx  

nginx编译参数说明如下:

--prefix=<path> -- 安装路径,如果没有指定,默认为/usr/local/nginx。

--sbin-path=<path> -- nginx可执行命令的文件,如果没有指定,默认为<prefix>/sbin/nginx。

--conf-path=<path> -- 在没有使用-c参数指定的情况下nginx.conf的默认位置,如果没有指定,默认为<prefix>/conf/nginx.conf。

--pid-path=<path> -- nginx.pid的路径,如果没有在nginx.conf中通过“pid”指令指定,默认为<prefix>/logs/nginx.pid。

--lock-path=<path> -- nginx.lock文件路径,如果没有指定,默认为<prefix>/logs/nginx.lock。

--error-log-path=<path> -- 当没有在nginx.conf中使用“error_log”指令指定时的错误日志位置,如果没有指定,默认为<prefix>/logs/error.log。

--http-log-path=<path> -- 当没有在nginx.conf中使用“access_log”指令指定时的访问日志位置,如果没有指定,默认为<prefix>/logs/access.log。

--user=<user> -- 当没有在nginx.conf中使用“user”指令指定时nginx运行的用户,如果没有指定,默认为“nobody”。

--group=<group> -- 当没有在nginx.conf中使用“user”指令指定时nginx运行的组,如果没有指定,默认为“nobody”。

--builddir=DIR -- 设置构建目录。

--with-rtsig_module -- 启用rtsig模块。

--with-select_module --without-select_module -- 如果在configure的时候没有发现kqueue, epoll, rtsig或/dev/poll其中之一,select模块始终为启用状态。

--with-poll_module --without-poll_module -- 如果在configure的时候没有发现kqueue, epoll, rtsig或/dev/poll其中之一,poll模块始终为启用状态。

--with-http_ssl_module -- 启用ngx_http_ssl_module,启用SSL支持并且能够处理HTTPS请求。需要OpenSSL,在Debian系统中,对应的包为libssl-dev。

--with-http_realip_module -- 启用ngx_http_realip_module

--with-http_addition_module -- 启用ngx_http_addition_module

--with-http_sub_module -- 启用ngx_http_sub_module

--with-http_dav_module -- 启用ngx_http_dav_module

--with-http_flv_module -- 启用ngx_http_flv_module

--with-http_stub_status_module -- 启用”server status”(服务状态)页

--without-http_charset_module -- 禁用ngx_http_charset_module

--without-http_gzip_module -- 禁用ngx_http_gzip_module,如果启用,需要zlib包。

--without-http_ssi_module -- 禁用ngx_http_ssi_module

--without-http_userid_module -- 禁用ngx_http_userid_module

--without-http_access_module -- 禁用ngx_http_access_module

--without-http_auth_basic_module -- 禁用ngx_http_auth_basic_module

--without-http_autoindex_module -- 禁用ngx_http_autoindex_module

--without-http_geo_module -- 禁用ngx_http_geo_module

--without-http_map_module -- 禁用ngx_http_map_module

--without-http_referer_module -- 禁用ngx_http_referer_module

--without-http_rewrite_module -- 禁用ngx_http_rewrite_module。如果启用,需要PCRE包。

--without-http_proxy_module -- 禁用ngx_http_proxy_module

--without-http_fastcgi_module -- 禁用ngx_http_fastcgi_module

--without-http_memcached_module -- 禁用ngx_http_memcached_module

--without-http_limit_zone_module -- 禁用ngx_http_limit_zone_module

--without-http_empty_gif_module -- 禁用ngx_http_empty_gif_module

--without-http_browser_module -- 禁用ngx_http_browser_module

--without-http_upstream_ip_hash_module -- 禁用ngx_http_upstream_ip_hash_module

--with-http_perl_module -- 启用ngx_http_perl_module

--with-perl_modules_path=PATH -- 为perl模块设置路径

--with-perl=PATH -- 为perl库设置路径

--http-client-body-temp-path=PATH -- 为http连接的请求实体临时文件设置路径,如果没有指定,默认为<prefix>/client_body_temp

--http-proxy-temp-path=PATH -- 为http代理临时文件设置路径,如果没有指定,默认为<prefix>/proxy_temp

--http-fastcgi-temp-path=PATH - 为http fastcgi临时文件设置路径,如果没有指定,默认为<prefix>/fastcgi_temp

--without-http -- 禁用HTTP服务

--with-mail -- 启用IMAP4/POP3/SMTP代理模块

--with-mail_ssl_module -- 启用ngx_mail_ssl_module

--with-cc=PATH -- 设置C编译器路径

--with-cpp=PATH -- 设置C预处理器路径

--with-cc-opt=OPTIONS -- 变量CFLAGS中附加的参数,用于FreeBSD中的PCRE库,同样需要指定--with-cc-opt=”-I /usr/local/include”,如果我们使用select()函数则需要同时增加文件描述符数量,可以通过--with-cc-opt=”-D FD_SETSIZE=2048”指定。

--with-ld-opt=OPTIONS -- 通过连接器的附加参数,用于FreeBSD中的PCRE库,同样需要指定--with-ld-opt=”-L /usr/local/lib”。

--with-cpu-opt=CPU -- 指定编译的CPU,可用的值为: pentium, pentiumpro, pentium3, pentium4, athlon, opteron, amd64, sparc32, sparc64, ppc64

--without-pcre -- 禁用PCRE库文件,同时将禁用HTTP rewrite 模块,如果要在”location”指令中使用正则表达式,同样需要PCRE库。

--with-pcre=DIR -- 设置PCRE库源文件路径。

--with-pcre-opt=OPTIONS -- 在编译时为PCRE设置附加参数。

--with-md5=DIR -- 设置md5库源文件路径。

--with-md5-opt=OPTIONS -- 在编译时为md5设置附加参数。

--with-md5-asm -- 使用md5汇编源。

--with-sha1=DIR -- 设置sha1库源文件路径。

--with-sha1-opt=OPTIONS -- 在编译时为sha1设置附加参数。

--with-sha1-asm -- 使用sha1汇编源。

--with-zlib=DIR -- 设置zlib库源文件路径。

--with-zlib-opt=OPTIONS -- 在编译时为zlib设置附加参数。

--with-zlib-asm=CPU -- 为指定的CPU使用zlib汇编源进行优化,可用值为: pentium, pentiumpro。

--with-openssl=DIR -- 设置openssl库源文件路径。

--with-openssl-opt=OPTIONS -- 在编译时为openssl设置附加参数。

--with-debug -- 启用debug记录。

--add-module=PATH -- 增加一个在PATH中的第三方模块。

默认的安装路径为:/usr/local/nginx;跳转到其目录下sbin路径下,便可以启动或停止它了。

[plain] view
plain copy

 





# ./nginx -h  

nginx version: nginx/1.7.3  

Usage: nginx [-?hvVtq] [-s signal] [-c filename] [-p prefix] [-g directives]  

Options:  

  -?,-h         : this help  

  -v            : show version and exit  

  -V            : show version and configure options then exit  

  -t            : test configuration and exit  

  -q            : suppress non-error messages during configuration testing  

  -s signal     : send signal to a master process: stop, quit, reopen, reload  

  -p prefix     : set prefix path (default: /usr/local/nginx/)  

  -c filename   : set configuration file (default: conf/nginx.conf)  

  -g directives : set global directives out of configuration file  

启动:nginx
停止:nginx -s stop

3、添加到系统服务
使用命令“# vi /etc/init.d/nginx”,打开编辑器,输入如下内容:

[plain] view
plain copy

 





#!/bin/sh  

# chkconfig: 2345 85 15  

# Startup script for the nginx Web Server  

# description: nginx is a World Wide Web server.   

# It is used to serve HTML files and CGI.  

# processname: nginx  

# pidfile: /usr/local/nginx/logs/nginx.pid  

# config: /usr/local/nginx/conf/nginx.conf  

  

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin  

DESC="nginx deamon"  

NAME=nginx  

DAEMON=/usr/local/nginx/sbin/$NAME  

SCRIPTNAME=/etc/init.d/$NAME  

  

test -x $DAEMON || exit 0  

  

d_start(){  

  $DAEMON || echo -n "already running"  

}  

  

d_stop(){  

  $DAEMON -s quit || echo -n "not running"  

}  

  

  

d_reload(){  

  $DAEMON -s reload || echo -n "can not reload"  

}  

  

case "$1" in  

start)  

  echo -n "Starting $DESC: $NAME"  

  d_start  

  echo "."  

;;  

stop)  

  echo -n "Stopping $DESC: $NAME"  

  d_stop  

  echo "."  

;;  

reload)  

  echo -n "Reloading $DESC conf..."  

  d_reload  

  echo "reload ."  

;;  

restart)  

  echo -n "Restarting $DESC: $NAME"  

  d_stop  

  sleep 2  

  d_start  

  echo "."  

;;  

*)  

  echo "Usage: $ScRIPTNAME {start|stop|reload|restart}" >&2  

  exit 3  

;;  

esac  

  

exit 0  

保存退出后,再使用下面的命令,使其可执行;然后,添加配置并查看。
可用chkconfig修改其值,也可用ntsysv工具改变是否自启动。

[plain] view
plain copy

 





# chmod +x /etc/init.d/nginx  

# chkconfig --add nginx  

# chkconfig nginx on/off  

# chkconfig --list nginx  

nginx 0:off 1:off 2:on 3:on 4:on 5:on 6:off  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: