首页 > 其他 > 详细

安装nginx

时间:2019-07-22 18:48:35      阅读:90      评论:0      收藏:0      [点我收藏+]

1.下载nginx安装包和依赖包


wget http://nginx.org/download/nginx-1.15.9.tar.gz
wget http://ftp.pcre.org/pub/pcre/pcre-8.43.tar.gz
wget http://www.zlib.net/fossils/zlib-1.2.11.tar.gz

2.解压依赖包


tar -xzvf pcre-8.43.tar.gz -C /usr/local/myapps
tar -xzvf zlib-1.2.11.tar.gz -C /usr/local/myapps

3.解压nginx安装包


tar -xzvf nginx-1.15.9.tar.gz

4.安装编译依赖环境


yum -y install gcc-c++

5.安装nginx


cd nginx-1.15.9/
./configure --prefix=/usr/local/myapps/nginx --sbin-path=/usr/sbin/nginx --pid-path=/usr/local/myapps/nginx/logs/nginx.pid --error-log-path=/usr/local/myapps/nginx/logs/error.log --http-log-path=/usr/local/myapps/nginx/logs/access.log --with-pcre=/usr/local/myapps/pcre-8.43 --with-zlib=/usr/local/myapps/zlib-1.2.11 --with-http_stub_status_module --with-stream
make && make install
参数说明:
--with-http_stub_status_module  加载性能统计模块
--with-stream 加载四层负载均衡支持模块

6.验证


nginx -V

7.创建nginx运行用户


groupadd www
useradd -M -g www -s /sbin/nologin www

8.编写初始配置文件


mv /usr/local/myapps/nginx/conf/nginx.conf /usr/local/myapps/nginx/conf/nginx.conf_bak
mkdir /usr/local/myapps/nginx/conf/vhosts/
cat << EOF >/usr/local/myapps/nginx/conf/nginx.conf
user www www;
worker_processes  1;
events {
     worker_connections  1024;
}
http {
     include       mime.types;
     default_type  application/octet-stream;
     log_format  main  ‘$remote_addr - $remote_user [$time_local] $request $status $body_bytes_sent $http_referer $http_user_agent $http_x_forwarded_for‘;
     sendfile        on;
     keepalive_timeout  65;
     include /usr/local/myapps/nginx/conf/vhosts/http*.conf;
}
stream {
include /usr/local/myapps/nginx/conf/vhosts/tcp*.conf;
}
EOF
9.检查配置文件的正确性
nginx -t

10.启动nginx


nginx -c /usr/local/myapps/nginx/conf/nginx.conf

11.停止nginx


ps -ef | grep nginx | grep -v grep | awk ‘{print $2}‘ |xargs kill -9

12.重载配置文件


nginx -s reload

安装nginx

原文:https://www.cnblogs.com/jipinglong/p/11227651.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!