使用环境
系统环境:CentOS 7 nginx
版本:nginx-1.14.0
下载安装包
官网下载地址: https://nginx.org/download/nginx-1.14.0.tar.gz
安装依赖
1.gcc环境,已安装的可忽略
# yum install gcc gcc-c++
2.PCRE环境,正则表达式库
# yum install pcre pcre-devel
3.zlib环境,使用gzip功能
# yum install zlib zlib-devel
4.openssl环境,使用HTTPS功能
# yum install openssl openssl-devel
添加nginx用户
创建三无用户,用于启动nginx
# useradd -s /sbin/nologin -c "Nginx" -M nginx
编译安装
解压安装包
# tar -xvf nginx-1.14.0.tar.gz
# cd nginx-1.14.0
查看编译选项
# ./configure --help
开始编译,参数根据自己实际情况调整参考
# ./configure --prefix=/web/nginx --user=nginx --group=nginx --with-http_ssl_module --with-pcre
# make && make install
启动Nginx
# /web/nginx/sbin/nginx -c /web/nginx/conf/nginx.conf
修改配置文件
1.创建虚拟站点目录
# mkdir -p /web/nginx/conf/virtual-site
2.修改nginx.conf配置
# cd /web/nginx/conf
# vim nginx.conf
3.nginx.conf 示例
user nginx;
worker_processes 4;
error_log logs/error.log;
pid logs/nginx.pid;
events {
use epoll;
worker_connections 1024;
}
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;
client_max_body_size 0;
proxy_connect_timeout 90;
proxy_read_timeout 180;
proxy_send_timeout 180;
sendfile on;
keepalive_timeout 65;
gzip on;
include virtual-site/*.conf;
server {
listen 80;
server_name localhost;
location / {
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_pass http://127.0.0.1:8080;
}
location = /50x.html {
root html;
}
}
}
重启Nginx
# /web/nginx/sbin/nginx -s reload