nginx安装

mac2022-06-30  78

源码安装 1.安装一些必须的模块 yum install gcc gcc-c++ automake pcre pcre-devel zlip zlib-devel openssl openssl-devel  2.下载 wget http://nginx.org/download/nginx-1.8.1.tar.gz 3.解压 tar -zxvf nginx-1.8.1.tar.gz  4.进入目录 cd nginx-1.8.1 5.编译,生成makefile文件,编译时./configure --help以--without开头的都默认安装。 ./configure  --prefix=/usr/local/nginx  --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --error-log-path=/var/log/nginx/error.log  --http-log-path=/var/log/nginx/access.log  --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock  --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi --with-pcre 6.根据Makefile文件生成相应的模块 make 7.创建目录,并将生成的模块和文件复制到相应的目录 make install 8.修改原端口80为8090,以免和httpd的端口冲突(如果没有安装httpd,这一步省略) vim  /usr/local/nginx/conf/nginx.conf  server {         listen       8090;         server_name  localhost; 如果你安装了httpd,却没有进行这一步,启动时会报错,如下 [root@localhost sbin]# ./nginx  nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) nginx: [emerg] still could not bind() 9.创建这个文件夹 mkdir -p /var/tmp/nginx/client 如果不进行这一步,启动时会报错 [root@localhost nginx-1.8.1]# ./nginx

nginx: [emerg] mkdir() "/var/tmp/nginx/client/" failed (2: No such file or directory)

10. 创建nginx组和nginx用户

groupadd nginx

useradd nginx -g nginx

11. 如果报错如下

[root@localhost sbin]# ./nginx -c /usr/local/nginx/conf/nginx.conf [root@localhost sbin]# nginx: [emerg] open() "/var/run/nginx/nginx.pid" failed (2: No such file or directory)

解决办法:在/var/run下创建nginx文件,[root@localhost run]# mkdir nginx

yum安装

centos7中默认是没有nginx的rpm包的,所以我们自己需要先更新下rpm依赖库

(1) #rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

(2) #yum install nginx

 

一些操作命令 11,查看配置文件路径,并验证配置是否正确 [root@localhost sbin]# /usr/local/nginx/sbin/nginx -t 12. 查看nginx进程 [root@localhost sbin]# ps -ef |grep nginx  13.启动nginx程序 [root@localhost sbin]# ./nginx  或[root@localhost sbin]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf 14.从容停止(等待当前子进程处理完正在执行的请求后,结束 nginx 进程) [root@localhost sbin]# kill -quit 36657 15.快速停止 [root@localhost sbin]# kill -term 36679 或[root@localhost sbin]# kill -int 36679 16.强制停止 [root@localhost sbin]# pkill -9 nginx  或[root@localhost sbin]# ./nginx -s stop 17.重启 [root@localhost sbin]# ./nginx -s reload 或[root@localhost sbin]# ps -ef |grep nginx  root      37961      1  0 11:19 ?        00:00:00 nginx: master process ./nginx nginx     37981  37961  0 11:23 ?        00:00:00 nginx: worker process root      37983  32988  0 11:23 pts/0    00:00:00 grep nginx [root@localhost sbin]# kill -HUP 37961

 

转载于:https://www.cnblogs.com/fanren224/p/8457275.html

最新回复(0)