安裝 nginx
# rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
# 安装在目录:/etc/yum.repos.d/nginx.repo)
# yum install nginx
启动并查看状态
# 启动服务
systemctl start nginx
# 查看状态
systemctl status nginx
# 开机自启动
systemctl enable nginx
配置nginx
Http反向代理
编辑配置
# cd /etc/nginx/conf.d
# cp default.conf mysite.conf
修改mysite.conf 如下:
server {
listen 80;
server_name 192.168.0.18;
#access_log /var/log/nginx/pro.log;
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;
# 限制文件大小为1G
client_max_body_size 1024m;
# 指定代理服务器
proxy_pass http://127.0.0.1:8000;
}
location /static/ {
autoindex on;
alias /root/webapps/pro/static/; # 静态文件nginx处理
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
Tcp反向代理
注意tcp只能代理端口
stream {
upstream mysql {
hash $remote_addr consistent;
server MySQL_URL:3306 max_fails=3 fail_timeout=30s;
}
server {
listen 8000;
proxy_connect_timeout 30s;
proxy_timeout 600s;
proxy_pass mysql;
}
}
网友评论