Linux Centos下Nginx反向代理教程

  • A+
所属分类:系统文档

系统要求:CentOS系统,内存64MB及以上、80端口没有被占用

1、安装EPEL repo

rpm -Uvh http://mirror.ancl.hawaii.edu/linux/epel/6/i386/epel-release-6-8.noarch.rpm

EPEL repo下载地址:https://fedoraproject.org/wiki/EPEL

2、安装Nginx
安装Nginx

yum install nginx -y

调整Nginx配置

cd /etc/nginx/conf.d
mv default.conf default.conf.disabled

3、创建Nginx反代配置文件

cd /etc/nginx/conf.d
vi yourdomain.com                 

粘贴以下内容:

server {
      listen 80;
      server_name yourdomain.com;   
      access_log off;
      error_log off;
      location / {
      proxy_pass http://需要反代的服务器IP/;
      proxy_redirect off;
      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_max_temp_file_size 0;
      client_max_body_size 10m;
      client_body_buffer_size 128k;
      proxy_connect_timeout 90;
      proxy_send_timeout 90;
      proxy_read_timeout 90;
      proxy_buffer_size 4k;
      proxy_buffers 4 32k;
      proxy_busy_buffers_size 64k;
      proxy_temp_file_write_size 64k;
   }
} 

然后保存。

4、启动Nginx

service nginx start

  • 我的微信
  • 这是我的微信扫一扫
  • weinxin
  • 我的微信公众号
  • 我的微信公众号扫一扫
  • weinxin

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: