Skip to content
Snippets Groups Projects
Commit 1e651489 authored by Matthieu Benoist's avatar Matthieu Benoist
Browse files

ngninx configuration changes

parent e80d04d1
No related branches found
No related tags found
1 merge request!131SEO
...@@ -5,6 +5,14 @@ services: ...@@ -5,6 +5,14 @@ services:
build: build:
context: ./docker/dev/ context: ./docker/dev/
dockerfile: Dockerfile-rendertron dockerfile: Dockerfile-rendertron
networks:
- default
- grandlyon
labels:
- "traefik.frontend.rule=Host:rendertron.data.grandlyon.docker"
- "traefik.port=8083"
- "traefik.protocol=http"
- "traefik.docker.network=grandlyon"
proxy: proxy:
build: build:
...@@ -13,12 +21,16 @@ services: ...@@ -13,12 +21,16 @@ services:
volumes: volumes:
- ./docker/dev/nginx-development-proxy.conf:/etc/nginx/conf.d/default.conf - ./docker/dev/nginx-development-proxy.conf:/etc/nginx/conf.d/default.conf
labels: labels:
- "traefik.fronted.rule=Host:data.grandlyon.docker" - "traefik.frontend.rule=Host:data.grandlyon.docker"
- "traefik.port=80" - "traefik.port=80"
- "traefik.protocol=http"
- "traefik.docker.network=grandlyon" - "traefik.docker.network=grandlyon"
networks: networks:
- default default:
- grandlyon aliases:
- data.grandlyon.docker
grandlyon:
networks: networks:
grandlyon: grandlyon:
......
server { server {
# staging server is listening on the port 8180 # staging server is listening on the port 8180
listen 80; listen 80;
server_name data.grandlyon.docker; server_name data.grandlyon.docker proxy;
root /usr/share/nginx/html/; root /usr/share/nginx/html/;
set $en 0;
# rule serving the fr build
location / { location / {
try_files $uri $uri/ @prerender;
# try_files $uri$args /index.html; => used in the prerender =0 block
}
# Rule serving the en build
location /en {
#try_files $uri$args /en/index.html;
set $en 1;
}
# redirecting the /fr url to the new location of the fr build
location ~ ^/fr(.*)$ {
return 301 $scheme://$http_host$1$is_args$args;
}
location @prerender {
#proxy_set_header X-Prerender-Token YOUR_TOKEN;
set $prerender 0; set $prerender 0;
if ($http_user_agent ~* "googlebot|yahoo|bingbot|baiduspider|yandex|yeti|yodaobot|gigabot|ia_archiver|facebookexternalhit|twitterbot|linkedinbot|developers\.google\.com") { if ($http_user_agent ~* "googlebot|yahoo|bingbot|baiduspider|yandex|yeti|yodaobot|gigabot|ia_archiver|facebookexternalhit|twitterbot|linkedinbot|developers\.google\.com") {
set $prerender 1; set $prerender 1;
...@@ -38,23 +16,21 @@ server { ...@@ -38,23 +16,21 @@ server {
if ($http_user_agent ~ "Prerender") { if ($http_user_agent ~ "Prerender") {
set $prerender 0; set $prerender 0;
} }
# Dev only - allow to test request image when forcing the user agent.
if ($request_uri ~* "gif|png|jpg|pdf|svg|jpeg") {
set $prerender 0;
}
if ($prerender = 1) { if ($prerender = 1) {
rewrite .* /render/$scheme://$server_name$request_uri break; rewrite .* /render/http://$server_name$request_uri break;
proxy_pass http://rendertron:8083; proxy_pass http://rendertron:8083;
add_header Access-Control-Allow-Origin *;
} }
if ($en = 0) { if ($prerender = 0) {
rewrite .* /index.html break;
#sub_filter '<html lang="en">' '<html lang="fr">';
proxy_pass http://host.docker.internal:4200; proxy_pass http://host.docker.internal:4200;
add_header Access-Control-Allow-Origin *; add_header Access-Control-Allow-Origin *;
} }
if ($en = 1) {
rewrite .*/en/index.html break;
proxy_pass http://host.docker.internal:4200;
}
} }
#location /robots.txt { #location /robots.txt {
......
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
"scripts": { "scripts": {
"ng": "ng", "ng": "ng",
"start": "ng serve --proxy-config proxy.conf.json", "start": "ng serve --proxy-config proxy.conf.json",
"start-aot-fr": "ng serve --configuration=aot-fr", "start-aot-fr": "ng serve --configuration=aot-fr --disable-host-check",
"start-aot-en": "ng serve --configuration=aot-en", "start-aot-en": "ng serve --configuration=aot-en --disable-host-check",
"build-i18n:dev": "for lang in en fr; do node --max_old_space_size=4096 ./node_modules/@angular/cli/bin/ng build --configuration=development-$lang --delete-output-path false; done", "build-i18n:dev": "for lang in en fr; do node --max_old_space_size=4096 ./node_modules/@angular/cli/bin/ng build --configuration=development-$lang --delete-output-path false; done",
"build-i18n:prod": "for lang in en fr; do node --max_old_space_size=4096 ./node_modules/@angular/cli/bin/ng build --configuration=production-$lang --delete-output-path false; done", "build-i18n:prod": "for lang in en fr; do node --max_old_space_size=4096 ./node_modules/@angular/cli/bin/ng build --configuration=production-$lang --delete-output-path false; done",
"win-build-i18n:fr": "node --max_old_space_size=2048 ./node_modules/@angular/cli/bin/ng build --configuration=development-fr --delete-output-path false", "win-build-i18n:fr": "node --max_old_space_size=2048 ./node_modules/@angular/cli/bin/ng build --configuration=development-fr --delete-output-path false",
......
...@@ -27,6 +27,17 @@ Using the npm script (which use the Angular CLI): ...@@ -27,6 +27,17 @@ Using the npm script (which use the Angular CLI):
npm run start npm run start
``` ```
### Using with rendertron
Add 127.0.0.1 data.grandlyon.docker rendertron.data.grandlyon.docker to your host
Run the container with
```bash
docker-compose -f docker-compose-developement.rendertron.yml up -d
```
Start the web application with npm. You can no acces to both app and SSR version through the 2 domains aforesaid.
### Build the application ### Build the application
We defined in the package.json two scripts that can build the application. One that generates an optimized build and the other an unoptimized build. The optimized build takes longer than the normal one. We defined in the package.json two scripts that can build the application. One that generates an optimized build and the other an unoptimized build. The optimized build takes longer than the normal one.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment