无法修复nginxredirect到端口8080访问URL时不使用斜杠

我一直在试图解决这个如此烦人的错误,但没有奏效。 在这篇文章中,我遵循并尝试了很多方法, 当访问不带斜杠的URL时,Nginxredirect到端口8080,但仍然存在。

我正在使用nginx广告反向代理阿帕奇。 这是我的nginxconfiguration文件:

server { listen 80; ## listen for ipv4 #listen [::]:80 default ipv6only=on; ## listen for ipv6 server_name domain.com *.domain.com; #access_log /var/log/nginx/localhost.access.log; location / { proxy_pass http://127.0.0.1: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; } location ~* \.(jpg|jpeg|png|gif|png|css|js|swf)$ { root /var/www/html/domain/; } } 

和http

 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; access_log off; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 15; client_max_body_size 5M; gzip on; gzip_min_length 1100; gzip_buffers 4 32k; gzip_types text/plain application/x-javascript text/xml text/css; proxy_cache_path /var/cached levels=2:2 keys_zone=cache:1024m inactive=1d max_size=3900m; server_name_in_redirect off; server_names_hash_max_size 2048; server_names_hash_bucket_size 256; server_tokens off; ignore_invalid_headers on; client_header_timeout 3m; client_body_timeout 3m; send_timeout 3m; reset_timedout_connection on; connection_pool_size 256; client_header_buffer_size 256k; large_client_header_buffers 4 256k; request_pool_size 32k; output_buffers 4 32k; postpone_output 1460; fastcgi_hide_header X-Powered-By; include /etc/nginx/conf.d/*.conf; } 

这可能与您的后端软件有关,将端口8080写入输出。 如果没有select停止这样做,则可以通过在端口80上运行后端来解决问题。 只要确保在nginx.conf明确指定侦听外部IP ,而后端侦听本地IP

nginx.conf ,find没有任何IP或0.0.0.0 IP的每个listen指令,并将其更改为有一个:

 listen 80; ## listen for ipv4 

改成:

 listen <your external IP>:80; ## listen for ipv4 

在apacheconfiguration中find每个ListenVirtualHost指令并确保它们监听本地IP的端口80:

 Listen 8080 

改成

 Listen 127.0.0.1:80 

 <VirtualHost 0.0.0.0:8080> 

 <VirtualHost 127.0.0.1:80> 

最后,将nginx.conf中的proxy_pass指令更改为新的后端地址:

 proxy_pass http://127.0.0.1:80/; 

如果你想有几个后端,只要将它们放在任何其他本地IP(127.0.0.0/8)上,如下所示:

 <VirtualHost 127.0.0.2:80> <VirtualHost 127.0.0.3:80> <VirtualHost 127.0.0.4:80> 

nginx.conf的proxy_pass将是:

 proxy_pass http://127.0.0.2:80/; proxy_pass http://127.0.0.3:80/; proxy_pass http://127.0.0.4:80/; 

等等