Linux Centos下Nginx反向代理教程 |
主机要求:Centos系统,内存64MB及以上、80端口没有被占用 1. Yum update -y 2. Yum remove httpd -y 1. rpm -Uvh http://mirror.ancl.hawaii.edu/linux/epel/6/i386/epel-release-6-8.noarch.rpm 2. EPEL repo下载地址:https://fedoraproject.org/wiki/EPEL 安装Nginx 1. yum install nginx -y 调整Nginx配置 cd /etc/nginx/conf.d mv default.conf default.conf.disabled 1. cd /etc/nginx/conf.d 2. vi yourdomain.com 粘贴以下内容: 1. server { 2. listen 80; 3. server_name yourdomain.com; 4. access_log off; 5. error_log off; 6. location / { 7. proxy_pass http://需要反代的服务器IP/; 8. proxy_redirect off; 9. proxy_set_header Host $host; 10. proxy_set_header X-Real-IP $remote_addr; 11. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 12. proxy_max_temp_file_size 0; 13. client_max_body_size 10m; 14. client_body_buffer_size 128k; 15. proxy_connect_timeout 90; 16. proxy_send_timeout 90; 17. proxy_read_timeout 90; 18. proxy_buffer_size 4k; 19. proxy_buffers 4 32k; 20. proxy_busy_buffers_size 64k; 21. proxy_temp_file_write_size 64k; 22. } 23. } 然后保存。 1. iptables -I INPUT 5 -m state --state NEW -p tcp --dport 80 -j ACCEPT 2. service iptables save 3. service iptables restart 1. service nginx start |