下载地址:http://nginx.org/en/download.html
安装版本:1.10.0

安装配置如下:

 

/etc/nginx 目录

 

/home/nginx目录

 

--prefix=/home/nginx --sbin-path=/usr/sbin/nginx --conf-path=/home/nginx/conf/nginx.conf --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module

 

安装Nginx时报错

./configure: error: the HTTP rewrite module requires the PCRE library.
安装pcre-devel解决问题
yum -y install pcre-devel
 
如果报openssl错误,安装openssl-deve就可以
yum -y install openssl-devel

 

下图是没有添加任何配置参数的截图:./configure

 

启动时如果报错:

[emerg]: getpwnam(“nginx”) failed

需要添加用户和用户组nginx:
adduser -r -M -U nginx



关于安装配置,官方页面提供的配置如下:
--prefix=/etc/nginx
--sbin-path=/usr/sbin/nginx
--conf-path=/etc/nginx/nginx.conf
--error-log-path=/var/log/nginx/error.log
--http-log-path=/var/log/nginx/access.log
--pid-path=/var/run/nginx.pid
--lock-path=/var/run/nginx.lock
--http-client-body-temp-path=/var/cache/nginx/client_temp
--http-proxy-temp-path=/var/cache/nginx/proxy_temp
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp
--http-scgi-temp-path=/var/cache/nginx/scgi_temp
--user=nginx
--group=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_mp4_module
--with-http_gunzip_module
--with-http_gzip_static_module
--with-http_random_index_module
--with-http_secure_link_module
--with-http_stub_status_module
--with-http_auth_request_module
--with-threads
--with-stream
--with-stream_ssl_module
--with-http_slice_module
--with-mail
--with-mail_ssl_module
--with-file-aio
--with-http_v2_module
--with-ipv6

 

相关配置说明如下:

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

--sbin-path=<path> - Nginx可执行文件安装路径。只能安装时指定,如果没有指定,默认为<prefix>/sbin/nginx。

--conf-path=<path> - 在没有给定-c选项下默认的nginx.conf的路径。如果没有指定,默认为<prefix>/conf/nginx.conf。

--pid-path=<path> - 在nginx.conf中没有指定pid指令的情况下,默认的nginx.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 - 指定编译的目录

 

配置nginx启动脚本:

 

将附件中的nginx脚本保存到/etc/init.d/nginx文件,并修改两个地方:

nginx=”/usr/sbin/nginx” 修改成nginx执行程序的路径。

conffile=”/etc/nginx/nginx.conf” 修改成配置文件的路径。

保存后,就可以通过该脚本对nginx服务进行管理了:

使用chkconfig进行管理

上面的方法完成了用脚本管理nginx服务的功能,但是还是不太方便,比如要设置nginx开机启动等。这时可以使用chkconfig来设置。

先将nginx服务加入chkconfig管理列表:

chkconfig --add /etc/init.d/nginx

加完这个之后,就可以使用service对nginx进行启动,重启等操作了。

$ service nginx start
$ service nginx stop
$ service nginx reload
...

设置终端模式开机启动:

$ chkconfig --level 3 nginx on

 

附件中nginx为启动脚本 nginx启动脚本

 

Centos 7 添加服务启动方法:

CentOS 7的服务systemctl脚本存放在:/usr/lib/systemd/,有系统(system)和用户(user)之分,需要开机不登陆就能运行的程序,存在系统服务里,即:/usr/lib/systemd/system目录下。

启动脚本放到路径/usr/lib/systemd/system/下,执行systemctl enable nginx.service令既可以完成开机启动服务的设置

操作服务相关的命令:

设置开机自启动
systemctl enable nginx.service

手动启动nginx服务
systemctl start nginx.service

停止开机自启动
systemctl disable nginx.service

查看服务当前状态
systemctl status nginx.service

重新启动服务
systemctl restart nginx.service

posted on 2018-03-27 17:30  jaamy  阅读(180)  评论(0编辑  收藏  举报