nginx 安装、配置、负载均衡、反向代理<一>
来源:互联网 发布:js改变浏览器窗口大小 编辑:程序博客网 时间:2024/06/03 19:42
nginx 安装
本文主讲nginx的安装
nginx的负载均衡,反向代理,gzip压缩配置等,详见:nginx 安装、配置、负载均衡、反向代理<二>
准备工作: 一台能联公网的CentOS 7.x服务器
# root 登录(因为要使用80端口,一般情况下需要root权限) cd ~ # 新建nginx用户和nginx组 groupadd -r nginx && useradd -r -g nginx -s /bin/false -M nginx # yum安装nginx必须的依赖库(已安装的会自动监测是否为最新并升级到最新版本) yum -y install openssl openssl-devel libxml2-devel libxslt-devel perl-devel perl-ExtUtils-Embed # 官网下载Nginx1.9.0的tar包,然后解压到服务器上 wget -c http://nginx.org/download/nginx-1.9.0.tar.gz tar -zxf nginx-1.9.0.tar.gz && cd nginx-1.9.0 # 下载pcre的tar包并解压,以便支持Nginx的Rewrite功能 wget -c https://o3cex9zsl.qnssl.com/libs/nginx/pcre-8.36.tar.gz && tar -zxf pcre-8.36.tar.gz # 下载zlib的tar包并解压,以便支持Nginx的Gzip压缩功能 wget -c https://o3cex9zsl.qnssl.com/libs/nginx/zlib-1.2.8.tar.gz && tar -zxf zlib-1.2.8.tar.gz # 新建Nginx1.9.0安装时所需要的目录 cd /var/tmp/ && mkdir -p /var/tmp/nginx/{client,proxy,fastcgi,uwsgi,scgi} mkdir -p /var/run/nginx && cd ~/nginx-1.9.0 # 至此,准备工作基本完成
配置安装参数
# 执行 ./configure 命令安装,下面是完整的路径配置和安装,__注意不能有换行__,具体配置含义见文末 ./configure --prefix=/usr/share/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/nginx.pid --lock-path=/var/lock/nginx.lock --user=nginx --group=nginx --with-http_ssl_module --with-http_spdy_module --with-http_dav_module --with-http_flv_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_stub_status_module --with-http_sub_module --with-http_random_index_module --with-http_degradation_module --with-http_secure_link_module --with-http_gzip_static_module --with-http_perl_module --with-pcre=pcre-8.36 --with-zlib=zlib-1.2.8 --with-debug --with-file-aio --with-mail --with-mail_ssl_module --http-client-body-temp-path=/var/tmp/nginx/client_body --http-proxy-temp-path=/var/tmp/nginx/proxy --http-fastcgi-temp-path=/var/tmp/nginx/fastcgi --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi --with-stream --with-ld-opt="-Wl,-E"
编译和安装
# 执行make编译,make install 安装(可能需要时间稍微长点儿,几分钟到十几分钟,请耐心等待) make && make install # 测试安装是否成功,能显示版本号就说明没问题 nginx -v
配置nginx的操作命令和开机自动重启
# 进入root目录 cd ~ # 编辑nginx文件 vi nginx # 文件内容如下,粘贴时注意核对下有没有漏掉,然后保存退出 # 添加到systemctl初始化目录中 mv ~/nginx /etc/init.d/nginx && chmod +x /etc/init.d/nginx # 删除不必要的文件夹 rm -rf nginx-1.9.0* # 添加开机启动 chkconfig --add nginx chkconfig nginx on
nginx命令配置文件的内容
#! /bin/bash # # nginx - this script starts and stops the nginx daemon # # chkconfig: - 85 15 # description: Nginx is an HTTP(S) server, HTTP(S) reverse \ # proxy and IMAP/POP3 proxy server # # processname: nginx # config: /etc/nginx/nginx.conf # pidfile: /var/run/nginx/nginx.pid # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ "$NETWORKING" = "no" ] && exit 0 nginx="/usr/sbin/nginx" prog=$(basename $nginx) NGINX_CONF_FILE="/etc/nginx/nginx.conf" [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx lockfile=/var/lock/nginx.lock start() { [ -x $nginx ] || exit 5 [ -f $NGINX_CONF_FILE ] || exit 6 echo -n $"Starting $prog: " daemon $nginx -c $NGINX_CONF_FILE retval=$? echo [ $retval -eq 0 ] && touch $lockfile return $retval } stop() { echo -n $"Stopping $prog: " killproc $prog -QUIT retval=$? echo [ $retval -eq 0 ] && rm -f $lockfile return $retval } restart() { configtest || return $? stop sleep 1 start } reload() { configtest || return $? echo -n $"Reloading $prog: " killproc $nginx -HUP RETVAL=$? echo } force_reload() { restart } configtest() { $nginx -t -c $NGINX_CONF_FILE } rh_status() { status $prog } rh_status_q() { rh_status >/dev/null 2>&1 } case "$1" in start) rh_status_q && exit 0 $1 ;; stop) rh_status_q || exit 0 $1 ;; restart|configtest) $1 ;; reload) rh_status_q || exit 7 $1 ;; force-reload) force_reload ;; status) rh_status ;; condrestart|try-restart) rh_status_q || exit 0 ;; *) echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}" exit 2 esac
测试安装和配置结果
# nginx 版本 nginx -v # 启动Nginx服务 systemctl start nginx # 停止nginx服务 systemctl stop nginx # 重启Nginx服务 systemctl restart nginx # 服务的状态(可以查看当前nginx服务是否正常,以及报错原因) systemctl status nginx # 检查nginx.conf配置的合法性(一般用于编辑完nginx.conf文件后,看看编辑是否有问题) nginx -t
以上,安装工作完成 =================================================
附:nginx的安装参数详述
+ 参考资料:blog地址https://typecodes.com/web/centos7compilenginx.html
阅读全文
0 0
- nginx 安装、配置、负载均衡、反向代理<一>
- Centos7安装Nginx及配置反向代理和负载均衡
- nginx 安装、配置、负载均衡、反向代理<二>
- nginx反向代理配置,负载均衡
- nginx反向代理和负载均衡配置
- nginx 反向代理 负载均衡配置
- nginx反向代理、负载均衡配置
- nginx 反向代理和负载均衡配置
- Nginx反向代理以及负载均衡配置
- nginx配置实现反向代理&负载均衡
- Nginx 反向代理 负载均衡 虚拟主机配置
- 反向代理负载均衡Nginx
- nginx反向代理,负载均衡
- 负载均衡 反向代理 nginx
- nginx 反向代理-负载均衡
- Nginx 反向代理 + 负载均衡
- nginx反向代理负载均衡
- Nginx的介绍,安装和配置,Nginx的反向代理,负载均衡
- checkedListBoxControl的用法
- 1.2计算机网络的组成
- 特效Duang!!!----让控件抖一抖
- 数据库:取最近30天数据
- Java NIO系列教程(十) Java NIO DatagramChannel
- nginx 安装、配置、负载均衡、反向代理<一>
- 利用JDBC导出数据库并生成静态导航界面文件
- org.apache.commons.net.ftp.FTPClient
- 项目报错:Caused by: java.lang.SecurityException:
- Mysql 中的事件//定时任务
- idea开发-使用oracle数据库-mapper文件中-常用语句
- spring boot启动报错Error creating bean with name 'entityManagerFactory' defined in class path resource [
- Java AES加密
- javascript垃圾回收机制