CentOS 7 编译安装nginx记录

使用环境

系统环境: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

转载于:https://my.oschina.net/qinmei/blog/1835177

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值