I have been looking for a way to configure my Nginx to listen to POST requests of webhooks from Github.
I configured a new Webhook in Github as follows:
Payload URL: https://myUrl/payload Secret: thisisthesecret
My goal is to tell Nginx: once you receive POST request (Github webhook in my case), if the header you got matches "thisisthesecret" then return "OK" and put the payload under https://myUrl/payload
Except for this example I couldn't find any implementation of it online so I am reaching out to your assistance.
This is my current nginx.config file:
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
Related
I'm building a website that I'm running through a docker container. I am receiving this error
webserver_1 | 2019/10/01 17:50:24 [emerg] 1#1: unexpected "}" in /etc/nginx/nginx.conf:36
webserver_1 | nginx: [emerg] unexpected "}" in /etc/nginx/nginx.conf:36
All of the curly brackets are counted for and removing this one (it's the third to last brace) would leave me with an uneven number.
This is my nginx.conf. Does anyone know what's going on?
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
server {
location /api {
auth_basic 'closed site';
auth_basic_user_file /etc/nginx/conf.d/.htpasswd
}
}
}
The /etc/nginx/nginx.conf file looks by default like this:
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
I want to add something to the end of the http{} block, for example:
include /etc/nginx/sites-enabled/*.conf;
So that it becomes:
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*.conf;
}
It is important that it is not depending on any of the existing content, it should just take the closing bracket as the reference point.
I do currently have this code:
sed -i '/^http {/a\ include \/etc\/nginx\/sites\-enabled\/\*\.conf\;' /etc/nginx/nginx.conf
Unfortunately, that is inserting it at the start of the block, not the end.
This might work for you GNU sed):
sed '/^http {/,/^}/!b;/^}/i\new content' file
Use a range to focus on the http section and insert the new content before the closing }.
Can also be written:
sed -e '/^http {/,/^}/{/^}/i\new content' -e '}' file
I tried installing nginx with virtual hosting enabled with a single site currently hosted.
my nginx.conf
user nginxsite;
worker_processes 4;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
#server_names_hash_bucket_size 64;
}
I assume that the user nginxsite; is the useradd created for the root directory ownership. default of that is just nginx.
my virtual.conf inside /etc/nginx/conf.d/
server {
listen 80;
#listen *:80;
server_name www.nginxsite.domain.com *.nginxsite.domain.com;
#access_log /var/log/nginx/access.log
location / {
root /var/www/nginxsite.com/public_html/;
index index.html index.htm; }
}
The server name and ip has already been added in my hostfile
XX.XX.XX.XX www.nginxsite.domain.com
I'm pretty sure the issue lies in my conf files but I can't seem to point out where.
Checked the logs but there's nothing.
Please help.
Thanks so much!
Nginx directory is disexist under /usr/local.
My server's os is centos 7.2 64 bit.
error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid;
events {
worker_connections 1024; }
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf; }
I found it by mysself.
/usr/share/nginx/html
Ubuntu 15.10
Using this run command with the official nginx image:
sudo docker run -dit --name="myApp" -p 8181:80 -v /home/username/Documents/My\ Folder/Repos/my-app:/usr/share/nginx/html:ro -v /home/username/Documents/My\ Folder/Repos/my-app/nginx.conf:/etc/nginx/nginx.conf:ro nginx
It runs fine without the 2nd VOLUME declaration (without the custom nginx.conf), but I recently added it because I need to configure some things (AngularJS html5 routing mode).
My nginx.conf (All I did was add the location settings, everything else was copied over from the original):
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
location / {
root /home/username/Documents/My Folder/Repos/my-app;
try_files $uri index.html;
}
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
Your location block should be within a server block:
server {
location / {
root /home/username/Documents/My Folder/Repos/my-app;
try_files $uri index.html;
}
}
A tutorial for some more information: https://www.digitalocean.com/community/tutorials/understanding-the-nginx-configuration-file-structure-and-configuration-contexts#the-location-context