Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

1.4K
Vistas
Cómo ejecutar el script bash desde Nginx

1) Tengo un sitio estático y una varita para configurar "autopull" desde bitbucket.

2) Tengo webhook de bitbucket.

3) Tengo un script bash que hace "git pull"

¿Cómo puedo ejecutar este script cuando nginx captura la solicitud?

 server { listen 80; server_name example.ru; root /path/to/root; index index.html; access_log /path/to/logs/nginx-access.log; error_log /path/to/logs/nginx-error.log; location /autopull { something to run autopull.sh; } location / { auth_basic "Hello, login please"; auth_basic_user_file /path/to/htpasswd; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $host; } }

Intenté el servicio lua_block y fastcgi, pero ambos fallaron. lua no ejecuta os.execute("/path/to/script") y no escribe el registro. fastcgi tiene más éxito, pero no tiene permisos, porque mi usuario de www-data no tiene ssh-key en mi repositorio de bitbuchet.

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

Problema resuelto.

No quería usar ningún script/proceso en otro puerto porque tengo varios sitios y necesito un puerto para cada uno.

Mi configuración final es:

 server { listen 80; server_name example.ru; root /path/to/project; index index.html; access_log /path/to/logs/nginx-access.log; error_log /path/to/logs/nginx-error.log; location /autopull { content_by_lua_block { io.popen("bash /path/to/autopull.sh") } } location / { auth_basic "Hello, login please"; auth_basic_user_file /path/to/htpasswd; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $host; } }

El problema estaba en el permiso del usuario www-data y su ssh-kay en el repositorio.

over 4 years ago · Santiago Trujillo Denunciar

0

Basado en esto , crea un script py

 #!/usr/bin/python from BaseHTTPServer import BaseHTTPRequestHandler,HTTPServer from subprocess import call PORT_NUMBER = 8080 autopull = '/path/to/autopull.sh' command = [autopull] #This class will handles any incoming request from #the browser class myHandler(BaseHTTPRequestHandler): #Handler for the GET requests def do_GET(self): self.send_response(200) self.send_header('Content-type','text/html') self.end_headers() # Send the html message self.wfile.write("runing {}".format(autopull)) call(command) return try: #Create a web server and define the handler to manage the #incoming request server = HTTPServer(('', PORT_NUMBER), myHandler) print 'Started httpserver on port ' , PORT_NUMBER #Wait forever for incoming htto requests server.serve_forever() except KeyboardInterrupt: print '^C received, shutting down the web server' server.socket.close()

Ejecútelo y en la configuración de nginx agregue

 location /autopull { proxy_pass http://localhost:8080; }
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda