nginx学习(一):基本安装

简介: 转载自http://summervast.blog.51cto.com/690507/385511 注意:可能因版本不同,个别指令不起作用,需要注意版本灵活安装,我在安装时也遇到过此问题 开始学习nginx,初步安装nginx,先熟悉一下;参考网上的资料和涨宴老师书籍。

 

转载自http://summervast.blog.51cto.com/690507/385511 

注意:可能因版本不同,个别指令不起作用,需要注意版本灵活安装,我在安装时也遇到过此问题 

开始学习nginx,初步安装nginx,先熟悉一下;参考网上的资料和涨宴老师书籍。

http://nginx.org/en/download.html

下载需要的版本,0.7版本的是稳定版本,0.8的是开发版本,看个人所好,我用的是nginx-0.8.48;

一、安装

1、检查安装nginx的依赖性,nginx的模块需要第三方库的支持,检查是否安装下列库:
zlib、zlib-devel、openssl、openssl-devel、prce、prce-devel

[root@mgmserver ~]# rpm -qa |grep zlib
zlib-devel-1.2.3-3
zlib-1.2.3-3
[root@mgmserver tar_packet]# rpm -qa |grep openssl
openssl-0.9.8e-12.el5
openssl-devel-0.9.8e-12.el5
[root@mgmserver tar_packet]# rpm -qa |grep pcre
pcre-6.6-2.el5_1.7
pcre-devel-6.6-2.el5_1.7
[root@mgmserver tar_packet]# rpm -qa |grep gcc
compat-libgcc-296-2.96-138
compat-gcc-34-g77-3.4.6-4
gcc-c++-4.1.2-46.el5
libgcc-4.1.2-46.el5
compat-gcc-34-3.4.6-4
compat-gcc-34-c++-3.4.6-4
gcc-java-4.1.2-46.el5
gcc-4.1.2-46.el5
gccp-gfortran-4.1.2-46.el5
[root@mgmserver tar_packet]# rpm -qa |grep autoconf
autoconf-2.59-12
[root@mgmserver tar_packet]# rpm -qa |grep automake
automake-1.9.6-2.1
automake16-1.6.3-8
automake15-1.5-16
automake17-1.7.9-7
automake14-1.4p6-13
2、添加nginx使用的用户和组 ,
[root@mgmserver ~]# groupadd nginx                   #nginx使用的组;
[root@mgmserver ~]# useradd -g nginx nginx      #nginx使用用户;
3、安装
[root@mgmserver ~]# cd /home/tar_packet/
[root@mgmserver tar_packet]# tar -zxvf nginx-0.8.48.tar.gz -C /home/install_packet/
[root@mgmserver tar_packet]# cd ../install_packet/
[root@mgmserver install_packet]# cd nginx-0.8.48/
[root@mgmserver nginx-0.8.48]# ls
auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  README  src

[root@mgmserver nginx-0.8.48]# ./configure --prefix=/usr/local/nginx \
> --user=nginx \
> --group=nginx \
> --with-http_stub_status_module \     #启用“server status"页
> --with-http_ssl_module                       #开启http ssl模块,使nginx可以支持https请求,这个模块需要已经
                                                                         安装openssl       
checking for OS
 + Linux 2.6.18-164.el5 i686
checking for C compiler ... found
checking for gcc builtin atomic operations ... not found
checking for C99 variadic macros ... found
checking for gcc variadic macros ... found
checking for unistd.h ... found
checking for inttypes.h ... found
checking for limits.h ... found
checking for sys/filio.h ... not found
checking for sys/param.h ... found
checking for sys/mount.h ... found
checking for sys/statvfs.h ... found
checking for crypt.h ... found
checking for Linux specific features
checking for epoll ... found
checking for sendfile() ... found
checking for sendfile64() ... found
checking for sys/prctl.h ... found
checking for prctl(PR_SET_DUMPABLE) ... found
checking for sched_setaffinity() ... found
checking for crypt_r() ... found
checking for sys/vfs.h ... found
checking for poll() ... found
checking for /dev/poll ... not found
checking for kqueue ... not found
checking for crypt() ... not found
checking for crypt() in libcrypt ... found
checking for F_READAHEAD ... not found
checking for posix_fadvise() ... found
checking for O_DIRECT ... found
checking for F_NOCACHE ... not found
checking for directio() ... not found
checking for statfs() ... found
checking for statvfs() ... found
checking for dlopen() ... not found
checking for dlopen() in libdl ... found
checking for sched_yield() ... found
checking for SO_SETFIB ... not found
checking for PCRE library ... found
checking for OpenSSL library ... found
checking for zlib library ... found
creating objs/Makefile
checking for int size ... 4 bytes
checking for long size ... 4 bytes
checking for long long size ... 8 bytes
checking for void * size ... 4 bytes
checking for uint64_t ... found
checking for sig_atomic_t ... found
checking for sig_atomic_t size ... 4 bytes
checking for socklen_t ... found
checking for in_addr_t ... found
checking for in_port_t ... found
checking for rlim_t ... found
checking for uintptr_t ... uintptr_t found
checking for system endianess ... little endianess
checking for size_t size ... 4 bytes
checking for off_t size ... 8 bytes
checking for time_t size ... 4 bytes
checking for setproctitle() ... not found
checking for pread() ... found
checking for pwrite() ... found
checking for strerror_r() ... found but is not working
checking for gnu style strerror_r() ... found
checking for sys_errlist[] ... found
checking for localtime_r() ... found
checking for posix_memalign() ... found
checking for memalign() ... found
checking for mmap(MAP_ANON|MAP_SHARED) ... found
checking for mmap("/dev/zero", MAP_SHARED) ... found
checking for System V shared memory ... found
checking for struct msghdr.msg_control ... found
checking for ioctl(FIONBIO) ... found
checking for struct tm.tm_gmtoff ... found
checking for struct dirent.d_namlen ... not found
checking for struct dirent.d_type ... found

Configuration summary
  + using system PCRE library
  + using system OpenSSL library
  + md5: using OpenSSL library
  + sha1 library is not used
  + using system zlib library

  nginx path prefix: "/usr/local/nginx"
  nginx binary file: "/usr/local/nginx/sbin/nginx"
  nginx configuration prefix: "/usr/local/nginx/conf"
  nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
  nginx pid file: "/usr/local/nginx/logs/nginx.pid"
  nginx error log file: "/usr/local/nginx/logs/error.log"
  nginx http access log file: "/usr/local/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"


[root@mgmserver nginx-0.8.48]#make
[root@mgmserver nginx-0.8.48]#make install

二、启动nginx
[root@mgmserver nginx]# /usr/local/webserver/nginx/sbin/nginx -c /usr/local/webserver/nginx/conf/nginx.conf

参数"-c"指定了配置文件的路径,如果不加'-c"参数, nginx,会默认加载其安装目录中conf子目录中的nginx.conf文件。


 

 


[root@mgmserver nginx-0.8.48]# ps -ef |grep nginx

可以看到一个主nginx的进程信息,一个子进程;如果在安装过程指定了“-pid-path=<path>那么该文件就指定了nginx的主进程号,如果没有指定pid文件的存放路径,nginx.pid默认存放在nginx安装目录的logs子目录下,

[root@mgmserver logs]# ls
access.log  error.log  nginx.pid
[root@mgmserver logs]# cat nginx.pid
6019

三、nginx的信号控制

◆ TERM,INT 快速关闭

◆ QUIT 从容关闭

◆ HUP 平滑重启,重新加载配置文件

◆ USR1 重新打开日志文件,在切割日志时用途较大;

 USR2 平滑升级可执行程序

◆ WINCH 从容关闭工作进程

 

我们可以直接通过以下命令来完成平滑重启,省下寻找nginx主进程号的步骤;

kill   -"信号类型”    ‘/usr/local/nginx/logs/nginx.pid'或者nginx的主进程号

(1)、从容停止nginx

[root@mgmserver ~]# kill -QUIT 6019       #nginx主进程号
[root@mgmserver logs]# kill -QUIT `cat /usr/local/nginx/logs/nginx.pid`

(2)、快速停止nginx

[root@mgmserver logs]# kill -TERM /INT   nginx主进程号

 [root@mgmserver logs]# kill -TERM /INT   `cat /usr/local/nginx/logs/nginx.pid

(3)、强制停止所有的nginx进程

#pkill   -9 nginx

(4)、平滑重启nginx

修改了nginx的配置文件要重启nginx;重启之前要检查配置文件是否正确:

[root@mgmserver html]# /usr/local/nginx/sbin/nginx -t -c  /usr/local/nginx/conf/nginx.conf
the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
configuration file /usr/local/nginx/conf/nginx.conf test is successful

[root@mgmserver conf]# kill -HUP `cat /usr/local/nginx/logs/nginx.pid`

注意符号;
nginx的平滑重启

kill     -HUP Nginx主进程号

或者

kill     -HUP        ·nginx.pid文件按存放路径·

若转载请注明出处!若有疑问,请回复交流!
目录
相关文章
|
18天前
|
NoSQL 关系型数据库 Redis
mall在linux环境下的部署(基于Docker容器),Docker安装mysql、redis、nginx、rabbitmq、elasticsearch、logstash、kibana、mongo
mall在linux环境下的部署(基于Docker容器),docker安装mysql、redis、nginx、rabbitmq、elasticsearch、logstash、kibana、mongodb、minio详细教程,拉取镜像、运行容器
mall在linux环境下的部署(基于Docker容器),Docker安装mysql、redis、nginx、rabbitmq、elasticsearch、logstash、kibana、mongo
|
1月前
|
应用服务中间件 Linux 网络安全
2022年超详细在CentOS 7上安装Nginx方法(源码安装)
这篇文章提供了在CentOS 7系统上通过源码安装Nginx的详细步骤,包括从官网下载Nginx源码包、上传至虚拟机、解压、删除压缩包、编译安装前的配置、安装PCRE库(因为Nginx使用PCRE库解析正则表达式)、安装zlib和OpenSSL库(用于支持HTTPS协议)、重新编译Nginx、安装后启动Nginx服务、关闭服务、修改默认端口、以及重启服务测试等步骤。文章还提供了相关命令和操作截图,帮助用户更好地理解和执行安装过程。
2022年超详细在CentOS 7上安装Nginx方法(源码安装)
|
1月前
|
应用服务中间件 PHP nginx
Mac安装Nginx
Mac安装Nginx
23 2
Mac安装Nginx
|
24天前
|
缓存 应用服务中间件 nginx
安装nginx-http-flv-module模块
本文介绍如何为Nginx安装`nginx-http-flv-module`模块。此模块基于`nginx-rtmp-module`二次开发,不仅具备原模块的所有功能,还支持HTTP-FLV播放、GOP缓存、虚拟主机等功能。安装步骤包括:确认Nginx版本、下载相应版本的Nginx与模块源码、重新编译Nginx并加入新模块、验证模块安装成功。特别注意,此模块已包含`nginx-rtmp-module`功能,无需重复编译安装。
67 1
|
2月前
|
应用服务中间件 Linux 网络安全
|
1月前
|
应用服务中间件 Linux nginx
Linux虚拟机磁盘扩容、Docker容器磁盘满的问题、Docker安装nginx
这篇文章讨论了Linux虚拟机磁盘扩容的方法,包括外部配置、具体扩容步骤和扩容后的效果验证。同时,文章还涉及了Docker容器磁盘满的问题及其解决方法,如删除不必要的镜像和容器,以及调整Docker的安装路径。此外,还提到了意外情况的处理,例如误删除停止的容器后的应对措施。最后,文章还提供了使用Docker安装nginx的步骤和成功访问的截图。
Linux虚拟机磁盘扩容、Docker容器磁盘满的问题、Docker安装nginx
|
1月前
|
应用服务中间件 Linux nginx
在CentOS上使用源码包安装Nginx、以及手动启动Nginx的步骤过程
这篇文章介绍了在CentOS系统上使用Nginx源码包进行安装和配置的详细步骤,包括源码包的获取、解压、配置、编译、安装、启动验证以及注意事项。
68 0
在CentOS上使用源码包安装Nginx、以及手动启动Nginx的步骤过程
|
1月前
|
应用服务中间件 网络安全 nginx
运维专题.Docker+Nginx服务器的SSL证书安装
运维专题.Docker+Nginx服务器的SSL证书安装
43 3
|
1月前
|
JavaScript 应用服务中间件 nginx
Windows安装hexo并配置nginx
Windows安装hexo并配置nginx
|
1月前
|
应用服务中间件 Shell 网络安全
nginx安装提示 libssl.so.3: cannot open shared object file: No
【8月更文挑战第1天】### 原因 未将安装的ssl中的`libssl.so.3`链接到`/usr/lib`导致缺失。 ### 解决方案 1. 检查openssl是否已安装,若为低版本则需重装。 ```sh whereis openssl
437 6