centOS7 安装NGINX 同时支持tcp 代理
1.安装 gcc gcc-c++:
yum -y install gcc gcc-c++
2.在/etc/yum.repo.d目录下创建文件:nginx.repo
vim /etc/yum.repos.d/nginx.repo
填写以下内容到文件中
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
3.安装nginx
yum install nginx
4.查看配置文件
cat /etc/nginx/nginx.conf
文件内容为:
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/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 /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
5.开启tcp代理, 用mysql做例子
编辑配置文件
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/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 /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
//新建配置内容,支持tcp代理
stream {
server {
listen 3306;
proxy_pass 192.168.0.15:3306;
}
}
6.允许系统启动nginx自启动
systemctl enable nginx
7.启动服务
service nginx start