<![CDATA[Latest posts for the topic " Lỗi 502 Bad Gateway nginx "]]> /hvaonline/posts/list/24.html JForum - http://www.jforum.net Lỗi 502 Bad Gateway nginx [root@Nginx ~]# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful  2. Selinux và Iptables:
[root@Nginx ~]# cat /etc/sysconfig/selinux # This file controls the state of SELinux on the system. # SELINUX= can take one of these three values: # enforcing - SELinux security policy is enforced. # permissive - SELinux prints warnings instead of enforcing. # disabled - No SELinux policy is loaded. SELINUX=disabled # SELINUXTYPE= can take one of these two values: # targeted - Targeted processes are protected, # mls - Multi Level Security protection. SELINUXTYPE=targeted  
[root@Nginx ~]# service iptables status iptables: Firewall is not running.  
3. Cấu hình nginx.conf
[root@Nginx ~]# cat /etc/nginx/nginx.conf user nobody; worker_processes 4; error_log logs/error.log crit; worker_rlimit_nofile 8192; events { worker_connections 1024; # you might need to increase this setting for busy servers use epoll; # Linux kernels 2.6.x change to epoll } http { server_names_hash_max_size 2048; server_names_hash_bucket_size 512; server_tokens off; include mime.types; default_type application/octet-stream; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 10; # Gzip on gzip on; gzip_min_length 1100; gzip_buffers 4 32k; gzip_types text/plain application/x-javascript text/xml text/css; # Other configurations ignore_invalid_headers on; client_max_body_size 8m; client_header_timeout 3m; client_body_timeout 3m; send_timeout 3m; connection_pool_size 256; client_header_buffer_size 4k; large_client_header_buffers 4 32k; request_pool_size 4k; output_buffers 4 32k; postpone_output 1460; # Cache most accessed static files open_file_cache max=10000 inactive=10m; open_file_cache_valid 2m; open_file_cache_min_uses 1; open_file_cache_errors on; # virtual hosts includes include "/etc/nginx/conf.d/*.conf"; }  
4. File Proxy
[root@Nginx ~]# cat /etc/nginx/conf.d/hienhai.com.conf server { listen 172.20.20.237:80; server_name hienhai.com hienhai.com; access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; location ~* .(gif|jpg|jpeg|png|ico|wmv|3gp|avi|mpg|mpeg|mp4|fl v|mp3|mid|js|css|html|htm|wml)$ { root /var/www/html/hienhai.com; expires 365d; } location / { client_max_body_size 10m; client_body_buffer_size 128k; proxy_send_timeout 90; proxy_read_timeout 90; proxy_buffer_size 128k; proxy_buffers 4 256k; proxy_busy_buffers_size 256k; proxy_temp_file_write_size 256k; proxy_connect_timeout 30s; proxy_wwwect http://www.hienhai.com:8080 http://www.hienhai.com; proxy_wwwect http://hienhai.com:8080 http://hienhai.com; proxy_pass http://172.20.20.238:8080/; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }  
5. Trên Apache: Đã thêm Virtualhost:
NameVirtualHost 172.20.20.238:8080 # Define Server document root DocumentRoot /var/www/html/ # Define the virtual host <VirtualHost 172.20.20.238:8080> ServerName www.hienhai.com ServerAlias hienhai.com DocumentRoot /var/www/html/hienhai.com <Directory "/var/www/html/hienhai.com"> Options FollowSymLinks -Includes AllowOverride All Order allow,deny Allow from all </Directory> RewriteEngine on </VirtualHost>  
- Đã chỉnh sửa :
Listen 8080  
- Đã cài đặt module:mod_rpaf với cấu hình như sau:
<IfModule mod_rpaf.c> RPAF_Enable On RPAF_ProxyIPs 127.0.0.1 172.20.20.237 RPAF_Header X-Forwarded-For RPAF_SetHostName On RPAF_SetHTTPS On RPAF_SetPort On </IfModule>  
- Đã Disabled Selinux và Stop Iptables. 6. Kết quả: Khi vào web thì hiển thị thông báo lỗi:
502 Bad Gateway nginx  
- Log Apache không có gì. - Log Nginx
[root@Nginx conf.d]# tail -f /var/log/nginx/access.log 172.20.20.138 - - [16/Feb/2014:09:37:58 +0700] "GET / HTTP/1.1" 502 166 "-" "Mozilla/5.0 (Windows NT 6.1; rv:27.0) Gecko/20100101 Firefox/27.0" 172.20.20.138 - - [16/Feb/2014:09:37:59 +0700] "GET /favicon.ico HTTP/1.1" 404 162 "-" "Mozilla/5.0 (Windows NT 6.1; rv:27.0) Gecko/20100101 Firefox/27.0" 172.20.20.138 - - [16/Feb/2014:09:37:59 +0700] "GET /favicon.ico HTTP/1.1" 404 162 "-" "Mozilla/5.0 (Windows NT 6.1; rv:27.0) Gecko/20100101 Firefox/27.0" 172.20.20.138 - - [16/Feb/2014:09:43:27 +0700] "GET / HTTP/1.1" 502 166 "-" "Mozilla/5.0 (Windows NT 6.1; rv:27.0) Gecko/20100101 Firefox/27.0" 172.20.20.138 - - [16/Feb/2014:09:43:32 +0700] "GET / HTTP/1.1" 502 166 "-" "Mozilla/5.0 (Windows NT 6.1; rv:27.0) Gecko/20100101 Firefox/27.0" 
]]>
/hvaonline/posts/list/45466.html#279805 /hvaonline/posts/list/45466.html#279805 GMT
Lỗi 502 Bad Gateway nginx /hvaonline/posts/list/45466.html#279813 /hvaonline/posts/list/45466.html#279813 GMT Lỗi 502 Bad Gateway nginx

tuanksor wrote:
Bạn kiểm tra lại xem apache có đang hoạt động bình thường không (truy cập trực tiếp ko qua proxy), kiểm tra iptables tại server apache đã accept port 8080 chưa. 
Hi tuanksor: - Trước khi cấu hình Nginx thì mình đã test thử Apache chạy Port 8080 OK. - Info mình đưa ra mình cũng đã nói là Iptables đã Stop luôn rồi]]>
/hvaonline/posts/list/45466.html#279816 /hvaonline/posts/list/45466.html#279816 GMT
Lỗi 502 Bad Gateway nginx Code:
#curl -IL http://172.20.20.238:8080
]]>
/hvaonline/posts/list/45466.html#279821 /hvaonline/posts/list/45466.html#279821 GMT