'Nginx proxy_pass doesn't send all of the request path to the server
The Environment:
I have a proxy server(nginx image) on port 80, an nginx server for backend on 81 and a backend(laravel) server on port 9000 all configured inside docker compose.
info:
In access.log file of nginx server I can see the url '/login' of 'GET' method is requested by proxy server but for some reason nginx server is only sending: '/' request to backend server.
I also checked the full url in backend with this facade Request::fullUrl() and it returns 'http://backend'.
Also if I uncomment # try_files $uri =404; line in nginx.conf it only responses with 404.
Question:
How can I fix that?
How can I send the whole url to my backend server?
docker-compose.yml file:
version: "3.8"
services:
nginx:
image: nginx
container_name: thecliniclaravel_nginx
ports:
- "80:80"
volumes:
- ./docker/nginx/nginx.conf:/etc/nginx/conf.d/default.conf:rw
- ./docker/log/nginx:/var/log/nginx:rw
networks:
- thecliniclaravel_bridge
depends_on:
- backend
backend:
container_name: thecliniclaravel_backend
build:
context: ./
volumes:
- thecliniclaravel_backend_vendor:/var/www/html/backend/vendor:rw
- .:/var/www/html/backend:rw
- ./docker/php/xdebug.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini:rw
- ./docker/php/addon.ini:/usr/local/etc/php/conf.d/addon.ini:rw
networks:
- thecliniclaravel_bridge
frontend:
container_name: thecliniclaravel_frontend
build:
context: ../thecliniclaravel_frontend
volumes:
- ../thecliniclaravel_frontend:/var/www/html/frontend:rw
networks:
- thecliniclaravel_bridge
volumes:
thecliniclaravel_backend_vendor: {}
networks:
thecliniclaravel_bridge:
driver: bridge
nginx.conf:
upstream backend {
server backend:9000;
keepalive 8;
}
# upstream frontend {
# server frontend:5000;
# }
index index.php;
server {
listen 80;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
proxy_set_header Host $host;
proxy_http_version 1.1;
proxy_set_header Connection "";
location /backend/ {
proxy_pass http://localhost:81/;
}
location /frontend/ {
proxy_pass http://localhost:82/;
}
}
server {
listen 81;
root /var/www/html/backend/public;
error_log /var/log/nginx/backend_error.log;
access_log /var/log/nginx/backend_access.log;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass backend;
fastcgi_index index.php;
fastcgi_keep_conn on;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param REDIRECT_STATUS 200;
}
}
server {
listen 82;
error_log /var/log/nginx/frontend_error.log;
access_log /var/log/nginx/frontend_access.log;
root /var/www/html/frontend/public;
#.
#.
#.
}
Solution 1:[1]
Omg, finally, i forgot to put this in the backend server block in nginx.conf file: include fastcgi_params;
It's absence was causing my backend to miss other parts of the request except the 'http://localhost'.
(Sometimes i just want smash my head toward this wall beside me.
any way thank you @user973254 )
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Hirbod |
