Si vous souhaitez utiliser un fichier nginx.conf personnalisé sur Google Kubernetes Engine, préparez-en un en étendant cet exemple de fichier nginx.conf.
Voici un extrait de la configuration requise par Cloud Endpoints :
http {
include /etc/nginx/mime.types;
server_tokens off;
client_max_body_size 32m;
upstream app_server {
server localhost:8081;
keepalive 128;
}
endpoints {
metadata_server;
}
server {
# Running port
listen 8080;
# Running ssl port
listen 443 ssl;
ssl_certificate /etc/nginx/ssl/nginx.crt;
ssl_certificate_key /etc/nginx/ssl/nginx.key;
# Logging to stdout enables better integration with Docker and GKE/Kubernetes.
access_log /dev/stdout;
location / {
# Begin Endpoints v2 Support
endpoints {
on;
# After ESP 1.7.0, "server_config" field is required.
# It has to be /etc/nginx/server_config.pb.txt exactly.
# If not present, some new features will not work.
server_config /etc/nginx/server_config.pb.txt;
# After ESP 1.7.0, "api" field is not required.
# If added, it has to be /etc/nginx/endpoints/service.json exactly.
# api /etc/nginx/endpoints/service.json;
# Uncomment the line below if you are not using Google Container Engine.
# The path should be set to the “-k” path specified in the ESP container’s
# args section in the Kubernetes yaml config.
# google_authentication_secret /etc/nginx/creds/service-account-creds.json;
}
# End Endpoints v2 Support
proxy_pass http://app_server;
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;
proxy_set_header X-Google-Real-IP $remote_addr;
# 86400 seconds (24 hours) is the maximum a server is allowed.
proxy_send_timeout 86400s;
proxy_read_timeout 86400s;
}
include /var/lib/nginx/extra/*.conf;
}
server {
# expose /nginx_status but on a different port to avoid
# external visibility / conflicts with the app.
listen 8090;
location /nginx_status {
stub_status on;
access_log off;
}
location / {
root /dev/null;
}
}
}
Créez maintenant une ConfigMap Kubernetes avec votre fichier nginx.conf personnalisé à l'aide de kubectl :
Modifiez le fichier de configuration Kubernetes, par exemple esp_echo_custom_config_gke.yaml, et remplacez SERVICE_NAME par le nom du service Endpoints.
Enfin, démarrez le service avec le fichier de configuration Kubernetes mis à jour à l'aide de kubectl.
kubectl create -f esp_echo_custom_config_gke.yaml
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2024/03/30 (UTC).
[{
"type": "thumb-down",
"id": "hardToUnderstand",
"label":"Hard to understand"
},{
"type": "thumb-down",
"id": "incorrectInformationOrSampleCode",
"label":"Incorrect information or sample code"
},{
"type": "thumb-down",
"id": "missingTheInformationSamplesINeed",
"label":"Missing the information/samples I need"
},{
"type": "thumb-down",
"id": "translationIssue",
"label":"Problème de traduction"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"Autre"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"Facile à comprendre"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"J'ai pu résoudre mon problème"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"Autre"
}]