I'm having issue allowing Cypress to test other routes besides "/" within CI builder.
I've come across this repo where core developer demoed how to run spec tests when services are created and managed using docker-compose.
Unfortunately the repo isn't demoing how can I get Cypress to test other routes. I'm getting 200 on "/" but getting 404 on others.
cypress.json:
{
1 "baseUrl": "http://nginx:80",
2 "video": false
3 }
docker-compose.yml:
services:
...
...
nginx:
build:
context: ./services/nginx
dockerfile: Dockerfile
restart: always
ports:
- 80:80
depends_on:
- users
- client
Root route gives 200 but all other throw 404:
CypressError: `cy.visit()` failed trying to load:
http://nginx:80/register
The response we received from your web server was:
> 404: Not Found
nginx.conf file:
server {
listen 80;
location / {
proxy_pass http://client:3000;
proxy_http_version 1.1;
proxy_redirect default;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
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_set_header X-Forwarded-Host $server_name;
}
location /users {
proxy_pass http://users:5000;
proxy_http_version 1.1;
proxy_redirect default;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
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_set_header X-Forwarded-Host $server_name;
}
location /auth {
proxy_pass http://users:5000;
proxy_http_version 1.1;
proxy_redirect default;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
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_set_header X-Forwarded-Host $server_name;
}
}
Related
Nginx Setup
AKAMAI
| +---> Nginx port 82
| |
-> AWS ELB/ALB -> Nginx Server(Port 80) -> Docker (Nginx Port 81) --|
|
+----> Nginx port 83
Browser sents request on HTTPS but Nginx server running on port 82/83 receiving x-forwarded-proto/scheme as http instead of https
Nginx Port 80 config
http {
...
server {
...
listen 80;
location / {
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
proxy_pass "http://127.0.0.1:81";
}
proxy_set_header HOST $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Scheme $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;
}
}
Nginx Port 81 config
server {
listen 81;
location ~ ^/v1/test {
proxy_pass http://127.0.0.1:82;
proxy_set_header HOST $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Scheme $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;
break;
}
location / {
proxy_set_header HOST $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Scheme $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;
proxy_pass http://127.0.0.1:83;
}
}
Nginx Port 82 Config
server {
...
listen 82;
proxy_set_header HOST $host;
proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;
}
Nginx Port 83 Config
server {
...
listen 83;
proxy_set_header HOST $host;
proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;
}
Applications running on port 82/83 are rails applications and use Passenger to serve the traffic.
Even we tried setting as below in 82/83 Nginx server configs
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-Scheme https;
I have an application with two github repos one for react and one for rails app. Requirement is all the routes should go to Rails server except routes starting with /catalog should go to to React app. Rails app server will communicate with React Server internally. SSL is configured on Nginx level.
I have created 3 different apps in heroku :
Rails server app
React server app
Web Server(Nginx)
My nginx server config looks like :
upstream rails {
server $HEROKU_APP_rails_URL;
}
upstream react {
server $HEROKU_APP_react_URL;
}
server {
listen $PORT;
server_name *.xyz.com;
# large_client_header_buffers 4 32k;
location / {
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_pass http://rails;
}
location /catalog {
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_pass http://react;
}
}
with above config I am getting HTTP 400 error on Nginx and it is not able to redirect the request. Please let me know what am i doing wrong.
Finally managed to solve this issue.. My nginx config looks like
upstream upstream_app_a {
server app_a.herokuapp.com:443;
}
upstream upstream_app_b {
server app_b.herokuapp.com:443;
}
server {
listen $PORT;
location / {
set $upstream upstream_app_a;
proxy_pass https://$upstream;
proxy_ssl_name app_a.herokuapp.com;
proxy_set_header x-forwarded-host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host app_a.herokuapp.com;
}
location /static {
set $upstream upstream_app_b;
proxy_pass https://$upstream/static;
proxy_set_header Host app_b.herokuapp.com;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /product_catalog {
set $upstream upstream_app_b;
proxy_pass https://$upstream;
proxy_ssl_name app_b.herokuapp.com;
proxy_set_header x-forwarded-host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host app_b.herokuapp.com;
}
}
Please make sure you set correct value for header
proxy_set_header Host app_a.herokuapp.com
We managed to solve this issue by referring to article
I have 3 website and running on docker port 8000, 8001, and 8002.
I'm configuring nginx with this config:
server {
server_name my.domain.net;
location / {
proxy_pass http://localhost:8000;
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_set_header X-Forwarded-Proto $scheme;
}
location /old {
proxy_pass http://127.0.0.1:8001;
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_set_header X-Forwarded-Proto $scheme;
}
location /new {
proxy_pass http://127.0.0.1:8002;
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_set_header X-Forwarded-Proto $scheme;
}
}
It works for location /, but for location /old and /new without all assets. I inspect element, for location /old the assets redirect to http://my.domain.net (absolutely 404 not found), where it should be http://my.domain.net/old/asset.css.
Need advice
Please help.
In your new and old applications hosted at 8081 and 8082 respectively, add assetsDir in your configuration.
vue.config.js:
module.exports = {
assetsDir: 'new'
}
I have a docker network running with this configuration (from docker-compose.yaml):
networks:
network:
driver: bridge
ipam:
driver: default
config:
- subnet: 172.28.1.0/24
(My network is named network)
I have an Angular frontend running in a container on this network (172.28.1.4). The frontend web server is an nginx server.
From the web server I would like calls to various backends (authentication and database) to go directly to these servers without exposing them to the outside world.
I.e to authenticate a user, something like this: httpClient.post('172.28.1.5:8080/_user/login', credentials)
I believe this should be done in the nginx configuration, but I am pretty clueless on how to allow access to 172.28.1.5 from nginx without exposing 172.28.1.5
The servers are visible to each other seen from a Docker perspective
I have tried using a reverse proxy and that works, but I cannot block access to the location from external ips
location ~/_user(/.*)*/?$ {
proxy_pass http://auth_server:8080; //auth_server points to 172.28.1.5
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_set_header X-Forwarded-Host $server_name;
}
The proxy setup. I have changed the names of the servers to clarify their role in the network.
The frontend can call the database_server like this:
http://external.ip.address:443/_api/any_path
Unfortunately, so can anyone else :)
server {
listen 443;
server_name localhost;
location ~/_user(/.*)*/?$ {
proxy_pass http://authentication_server:8080;
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_set_header X-Forwarded-Host $server_name;
}
location ~/_api(/.*)*/?$ {
proxy_pass http://database_server:80;
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_set_header X-Forwarded-Host $server_name;
}
location ~/ {
proxy_pass http://ui_frontend_server:8080;
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_set_header X-Forwarded-Host $server_name;
}
}
My docker setup makes this possible as it maps the name "authentication_server" with 172.28.1.3
authentication_server_service:
container_name: authentication_server
build: ../authentication_server/
image: authentication_server_image:latest
networks:
network:
ipv4_address: 172.28.1.3
I have following server structure:
first nginx, that redirects all requests to nginx in docker container. I want it just to handle https and proxy requests to nginx that cant handle https
Full config
Related config (nginx-recommended-proxy-headers here) (I just tried every header that could help, didn't work):
location / {
proxy_pass http://127.0.0.1:23000;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header X-Forwarded-Port $server_port;
proxy_set_header X-Forwarded-Ssl on;
proxy_set_header X-Forwarded-Protocol https;
proxy_set_header X-Url-Scheme https;
proxy_set_header X-Forwarded-Host $host:$server_port;
proxy_set_header X-Real_IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_pass_header Set-Cookie;
proxy_buffering off;
proxy_ssl_session_reuse off;
include /nix/store/avmqrlsy7dfh6bz1r6yzw3wvrvb0wzf1-nginx-recommended-proxy-headers.conf;
}
nginx in docker container. It glues rails server and responsivefilemanager. It exists to allow tesing of both server and filemanager, but does not handle https.
Docker-compose
nginx:
stdin_open: true
tty: true
extends:
file: chunks/nginx.yml
service: nginx
build:
args:
- NGINX_CACHE=on
ports:
- 23000:80
env_file:
- ./envs/filemanager-static-path.env
- ./envs/carrierwave-dirs.env
environment:
- BACKEND_URL=http://be:3000
- FILEMANAGER_URL=http://filemanager:80
volumes:
- filemanager_upload_data:/filemanager_upload_dir
- carrierwave_public_upload_data:/public_upload
- carrierwave_cache_data:/carrierwave_cache_dir
- ${SOURCE_DIR:-..}:/public
depends_on:
- be
- filemanager
Full config
Related config
location / {
proxy_pass $BACKEND_URL;
proxy_http_version 1.1;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Accept-Encoding "";
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Port $server_port;
proxy_set_header X-Forwarded-Host $host;
proxy_buffering off;
proxy_ssl_session_reuse off;
}
rails server, just rails server, default prod config
And with this config I have ActionController::InvalidAuthenticityToken issue.
Please help me. How this should work? What rails is expecting? https worked with this config when I had only 1 nginx and backend.
I've updated nixpkgs and issue disappeared