安装make:
yum -y install gcc automake autoconf libtool make
安装gcc:
yum -y install gcc gcc-c++
#nginx依赖的3个库的作用
gzip(解压缩)http模块需要 zlib 库
rewrite模块和解析正则表达式需要 pcre 库
ssl 功能需要openssl库
#yum -y install pcre pcre-devel
#yum -y install zlib zlib-devel
#yum -y install openssl openssl-devel
wget http://nginx.org/download/nginx-1.17.1.tar.gz
安装ssl: ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
make && make install
zlib、pcre的编译: #./configure
openssl的编译: #./config
#make && make install
ps:杀死80端口
fuser -k 80/tcp
一、启动停止命令
/usr/local/nginx/sbin目录下
1.启动
./nginx
2.停止
./nginx -s stop
3.重启
./nginx -s reload
二、配置
nginx配置详细:
user nginx;
#建议设置为cpu核数,这里为4核cpu,开启4个进程
worker_processes 4;
worker_cpu_affinity 0001 0010 0100 1000;
#配置nginx worker进程最大打开文件数
worker_rlimit_nofile 65535;
error_log logs/error.log;
pid logs/nginx.pid;
events{
use epoll; #事件模型
worker_connections 10240; #工作进程最大连接数量
}
http {
#文件扩展名与文件类型映射表
include mime.types;
#默认文件类型
default_type application/octet-stream;
#输出文件方式。注意:如果图片显示不正常,把on改为off
sendfile on;
#长连接超时时间,单位是秒
keepalive_timeout 65;
upstream backend {
#ip_hash;
server 192.168.0.211:8080 max_fails=2 fail_timeout=30s weight=2;
server 192.168.0.212:8080 max_fails=2 fail_timeout=30s weight=1;
}
server {
listen 80; #监听端口
server_name localhost; #主机名称
client_max_body_size 10M; #上传最大文件限制
location / {
proxy_psss http://backend;
index index.html index.htm;
#设定超时时间,单位为秒
proxy_connect_timeout 1;
proxy_read_timeout 1;
proxy_send_timeout 1;
}
#匹配任何以/test/开头的请求
location ^~/test/ {
alias /home/data/shared-folder/files/; #把请求映射为后面的固定路径
expires 24h; #设定页面缓存时间
}
#配置防盗链
location ~ .*\.(jpg|jpeg|JPG|png|gif|icon)$ {
valid_referers blocked http://www.xxxxxx.com www.xxxxxxx.com;
if ($invalid_referer) {
return 403;
}
}
#错误页面的重定向
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
server{
listen 443 ssl;
listen 80;
server_name www.baidu.com baidu.com;
ssl_certificate /usr/local/nginx/ssl/wnnwm.com.crt;
ssl_certificate_key /home/data/nginx/keys/wnnwm.com.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
rewrite ^/*$ /download/index.html last;
location / {
#防止都是请求头host
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# proxy_set_header Host $host;
# proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_next_upstream off;
proxy_set_header connection “”;
proxy_http_version 1.1;
proxy_pass http://192.168.1.60:80;
}
}
}
http转换成https页面
server{
listen 80;
server_name baidu.com www.baidu.com;
rewrite ^(.*) https://$host$1 permanent;
}