2.安装环境依赖
#安装gcc编译器
yum install gcc-c++
#安装PCRE 用于解析正则表达式
yum install -y pcre pcre-devel
#安装zlib 用于解压和压缩依赖
yum install -y zlib zlib-devel
#安装 SSL 套接字安全协议层 https
yum install -y openssl openssl-devel
3.解压和配置nginx
#解压nginx
tar nginx-1.20.2.tar.gz
#建立临时文件 否则后面会报错
mkdirs /opt/nginx_1.20.2/temp
#在cd 到nginx目录执行如下 如下命令 为了制作makefile
./configure \
--prefix=/opt/nginx_1.20.2 \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/opt/nginx_1.20.2/log/error.log \
--http-log-path=/opt/nginx_1.20.2/log/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/opt/nginx_1.20.2/temp/client \
--http-proxy-temp-path=/opt/nginx_1.20.2/temp/proxy \
--http-fastcgi-temp-path=/opt/nginx_1.20.2/temp/fastcgi \
--http-uwsgi-temp-path=/opt/nginx_1.20.2/temp/uwsgi \
--http-scgi-temp-path=/opt/nginx_1.20.2/temp/scgi \
--with-http_ssl_module --with-stream
#扫盲-->这里是注释不是命令 别拷贝
#prefix 指定nginx目录
#pid-path 指定nginx的pid
#lock-path 锁定安装文件 防止恶心篡改或误操作
#error-log 错误日志
#http-log-path http日志
#http-client-body-temp-path 启用gzip模块 在线实时压缩输出数据流
#http-proxy-temp-path设定客户端请求的临时目录
#http-fastcgi-temp-path 设定fastcgi临时目录
#http-uwsgi-temp-path 设置定uwsgi的临时目录
#http-scgi-temp-path 设置scgi的临时目录
#with-http_ssl_module https需要用到的模块
#with-stream tcp需要用到的模块
4.编译nginx
#编译nginx
make
#安装nginx
make install
#进入nginx sbin目录
cd /usr/local/nginx/sbin/
#启动nginx
./nginx
#停止命令
./nginx -s stop
#刷新配置
./nginx -s reload
5.常用命令以及自动启动
#本地虚拟机用需要先关闭防火墙的 阿里云和腾讯云 需要将80端口加入策略组
#查看当前防火墙状态
systemctl status firewalld
#关闭当前防火墙
systemctl stop firewalld
#开机防火墙不启动
systemctl disable firewalld
#配置开机自动启动(官网文件贴在最后 下面是需要注意的地方)
vim /etc/init.d/nginx
nginx=”/usr/local/nginx/sbin/nginx”
NGINX_CONF_FILE=”/usr/local/nginx/conf/nginx.conf”
#添加权限
chmod a+x /etc/init.d/nginx
#添加到nginx到chkconfig
chkconfig --add /etc/init.d/nginx
#添加到自动启动
chkconfig nginx on
#附
service nginx start
service nginx stop
service nginx restart
6.nginx.conf配置
worker_processes auto;
stream {
log_format tcp_format '$time_local|$remote_addr|$protocol|$status|$bytes_sent|$bytes_received|$session_time|$upstream_addr|$upstream_bytes_sent|$upstream_bytes_received|$upstream_connect_time';
access_log log/tcp-access.log tcp_format;
error_log log/tcp-error.log;
upstream app-name {
hash $remote_addr consistent;
server 127.0.0.1:3306 max_fails=3 fail_timeout=30s;
}
server {
listen 8012;
proxy_pass app-name;
proxy_timeout 20s;
proxy_connect_timeout 10s;
}
}
events {
worker_connections 51200;
multi_accept on;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml;
gzip_vary on;
gzip_proxied expired no-cache no-store private auth;
gzip_disable "MSIE [1-6]\.";
server {
listen 81;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
|