wget -c https://nginx.org/download/nginx-1.13.10.tar.gz
tar -zxvf nginx-1.13.10.tar.gz
// 依赖
yum install gcc
yum install pcre pcre-devel
yum install zlib zlib-devel
yum install openssl openssl-devel
// 编译安装
./configure
make && make install
whereis nginx // 查找安装位置
/usr/local/nginx/conf // 配置
/usr/local/nginx/logs // 日志
ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/nginx
nginx // 启动
nginx -t // 检查配置文件是否正确
nginx -c /etc/nginx.conf // 启动nginx,并制定配置文件
nginx -s stop // 相当于查出nginx的进程id然后kill
nginx -s quit // 待nginx进程处理完毕进行停止
nginx -s reload
nginx -s reopen
ps -aux | grep nginx
# nginx.conf文件
http {
include mime.types;
default_type application/octet-stream;
log_format myformat '$http_host - $remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for '
'"$upstream_addr" "$upstream_status" "$upstream_response_time" "$request_time"';
# myformat为定义的日志格式
access_log logs/access.log myformat;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
# 引入配置
include site/*.conf;
}
upstream demo {
#weigth参数表示权值,权值越高被分配到的几率越大
server x.x.x.x:8080 weight=1;
server x.x.x.x:8090 weight=1;
}
server {
listen 80;
server_name liangzai.pub;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
#请求转向upstream 名称 定义的服务器列表
proxy_pass http://demo ;
# Forward the user's IP address to Rails
# real_ip_header X-Real-IP;
}
}