目录
上传nginx-module-vst-master软件包并解压
1、Nginx服务基础
Nginx
Nginx ("engine x") 是一个高性能的 HTTP 和反向代理服务器。
稳定性高
系统资源消耗低
对HTTP并发连接的处理能力高
安装nginx
上传nginx-module-vst-master软件包并解压
tar -zxvf nginx-module-vts-master.zip
unzip nginx-module-vts-master.zip
mv nginx-module-vts-master /usr/local/
安装依赖包
yum -y install gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel make
编译安装nginx
首先将nginx-1.15.9.tar.gz上传到/opt目录下
cd /opt
tar -zxvf nginx-1.15.9.tar.gz
cd nginx-1.15.9/
开始编译
./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--add-module=/usr/local/nginx-module-vts-master
make -j4 && make install
优化管理
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin
useradd -M -s /sbin/nologin nginx
nginx -t #检查配置文件是否配置正确
nginx #启动
添加Nginx系统服务然后重启服务
vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx #描述
After=network.target #描述服务类别
[Service]
Type=forking #后台运行类型
PIDFile =/usr/local/nginx/logs/nginx.pid #PID文件位置
ExecStart=/usr/local/nginx/sbin/nginx #启动服务
ExecrReload=/bin/kill -s HUP $MAINPID #根据PID重载配置
ExecrStop=/bin/kill -s QUIT $MAINPID #根据PID终止进程
PrivateTmp=true
[Install]
WantedBy=multi-user.target #启动级别
chmod 754 /usr/lib/systemd/system/nginx.service #设置754权限是一种安全优化
systemctl start nginx.service
systemctl enable nginx.service
备份
cp /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak
vim /usr/local/nginx/conf/nginx.conf
#user nobody; #默认运行/管理用户
worker_processes 1; #工作进程运行数量,可配置成服务器内核数*2,如果网站访问量不大,一般设为1
#error_log logs/error.log; #错误日志文件路径/级别
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid; #pid文件位置
events { #events:事件
#use epoll #默认是没写的,epoll是抗高并发的参数之一
worker_connections 1024; #每个进程最多处理的连接数量(socket)上限是65535
PS:两种修改方式,以下是临时
#如提高每个进程的连接数还需执行“ulimit -n 65535”(临时调整)命令临时修改本地每个进程可以同时打开的最大文件数。
#在Linux 平台上,在进行高并发TCP连接处理时,最高的并发数量都要受到系统对用户单一进程同时可打开文件数量的限制
#可使用ulimit -a 命令查看系统允许当前用户进程打开的文件数限制。
}
http { #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"';
#access_log logs/access.log main; #访问日志位置
sendfile on; #支持文件发送(下载)
#tcp_nopush on; #此项允许或禁止使用socket的TCP_CORK的选项(发送数据包前先缓存数据),此选项仅在使用sendfile的时候使用
#keepalive_timeout 0; ##连接保持超时时间,单位:秒
keepalive_timeout 65;
#gzip on; #压缩模块 on 表示开启
server { #web服务相关的一些配置
listen 80; #默认的监听端口
server_name localhost; #站点域名,可以修改域名,例如www.liuxu.com
#charset koi8-r; #字符集支持(修改为中文)UTF-8
#access_log logs/host.access.log main; #此web服务的主访问日志
location / { #/根目录配置,(浏览器中,www.baidu.com/,访问的根路径
root html; #网站根目录的位置/usr/local/nginx/html(相对路径)
index index.html index.htm; #支持的首页文件格式
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html #当发生错误的时候能够显示一个预定义的错误页面
#
error_page 500 502 503 504 /50x.html; #当发生错误的时候能够显示一个预定义的错误页面
location = /50x.html { #错误页面配置
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80 #以下是支持PHP及跳转的配置
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server { #虚拟主机的配置文件
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server #HTTPS的配置(SSL 加密)
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}