I'm trying to use proxy_set_header directive in my nginx config to add a request header. However my nginx container can't be started due to this error.
So I check the nginx config in my container and it looks like the variable is empty and Nginx treat it as if there's a missing argument.
Here is my nginx.conf
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
server_names_hash_bucket_size 256;
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [cache:$upstream_cache_status] [$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;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/rss+xml text/javascript font/truetype font/opentype application/vnd.ms-fontobject image/svg+xml;
include /etc/nginx/conf.d/*.conf;
server {
listen 80;
server_name ${DOMAIN_NAME_CLIENT};
large_client_header_buffers 4 16k;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
proxy_read_timeout 1800;
proxy_connect_timeout 1800;
location /graphql {
auth_basic off;
proxy_pass http://${PRIVATE_IP_CLIENT}:3000;
proxy_set_header HOST nginx;
proxy_pass_request_headers on;
limit_except GET POST OPTIONS { deny all; }
}
location / {
auth_basic off;
limit_except GET POST { deny all; }
proxy_pass http://${PRIVATE_IP_CLIENT}:3000;
proxy_pass_request_headers on;
proxy_set_header proxied nginx;
}
}
}
We have a problem with Nginx. We have a converter server it's convert MP4 video to MP3 file and 300 user online, so when they start download their MP3 files at the same time, server time response become so huge like if it is freezed even if %vCPU doesn't exceeds 10% when he start the conversion using mpeg library.
My server Configuration :
16 vCPU.
RAM:30G
Data transfert :5TB.
Nginx Configuration (nginx.conf)
user www-data;
worker_processes auto;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
worker_rlimit_nofile 20240;
events {
worker_connections 4000;
multi_accept on;
use epoll;
}
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 off;
limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
server_tokens off;
client_header_timeout 10m;
client_body_timeout 10m;
send_timeout 10m;
client_max_body_size 700m;
connection_pool_size 256;
client_body_buffer_size 1024k;
client_header_buffer_size 8k;
keepalive_timeout 30;
keepalive_requests 100000;
reset_timedout_connection on;
open_file_cache max=200000 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 2;
open_file_cache_errors on;
gzip on;
gzip_min_length 10240;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml;
gzip_disable "MSIE [1-6]\.";
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
#include /etc/nginx/conf.d/*.conf;
}
Web site nginx configuration:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/html;
index index.php index.html index.htm;
client_max_body_size 700m;
connection_pool_size 256;
client_body_buffer_size 1024k;
client_header_buffer_size 8k;
limit_rate 125k;
limit_req zone=one burst=5;
# Make site accessible from http://localhost/
server_name localhost;
location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
}
Do you know where the problem may come ?
i got this Error :
"server" directive is not allowed here in /usr/local/apps/nginx/etc/conf.d/mydomain.com.conf:1
nginx: configuration file /usr/local/apps/nginx/etc/nginx.conf test failed
i use with Webuzo control panel + Lemp Stack from there .
this what i did...
i configured nginx.conf to this settings:
#user www-data;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
pid /usr/local/apps/nginx/var/log/nginx.pid;
events {
worker_connections 1024;
}
http {
# Let NGINX get the real client IP for its access logs
set_real_ip_from 127.0.0.1;
real_ip_header X-Forwarded-For;
# Basic Settings
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 20;
client_max_body_size 15m;
client_body_timeout 60;
client_header_timeout 60;
client_body_buffer_size 1K;
client_header_buffer_size 1k;
large_client_header_buffers 4 8k;
send_timeout 60;
reset_timedout_connection on;
types_hash_max_size 2048;
server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /usr/local/apps/nginx/etc/mime.types;
default_type application/octet-stream;
# Logging Settings
error_log /usr/local/apps/nginx/var/log/error_log debug;
access_log /usr/local/apps/nginx/var/log/web.access.log;
# Log Format
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
# Gzip Settings
gzip on;
gzip_static on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_min_length 512;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/css text/javascript text/xml text/plain text/x-component
application/javascript application/x-javascript application/json
application/xml application/rss+xml font/truetype application/x-font-ttf
font/opentype application/vnd.ms-fontobject image/svg+xml;
include /usr/local/apps/nginx/etc/conf.d/*.conf;
}
and after that i checked with nginx -t and it was ok...
I continued to the next file mydomain.com.conf and this what i putted there:
server {
listen 127.0.0.1:8080;
server_name mydomain.com;
port_in_redirect off;
server_tokens off;
autoindex off;
client_max_body_size 15m;
client_body_buffer_size 128k;
access_log /usr/local/apps/nginx/var/log/mydomain.com.log main;
error_log /usr/local/apps/nginx/var/log/mydomain.com.err;
root /home/www-data/public_html;
index index.php index.html index.htm;
try_files $uri $uri/ /index.php;
error_page 404 /404.html;
location = /404.html {
root /usr/local/apps/nginx/etc//html;
}
# Define default caching of 24h
expires 86400s;
add_header Pragma public;
add_header Cache-Control "max-age=86400, public, must-revalidate, proxy-revalidate";
# Redirect server error pages to static 50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/local/apps/nginx/etc//html;
}
# Don't log robots.txt requests
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
# Rewrite for versioned CSS+JS via filemtime
location ~* ^.+.(css|js) {
rewrite ^(.+).(d+).(css|js)$ $1.$3 last;
expires 31536000s;
access_log off;
log_not_found off;
add_header Pragma public;
add_header Cache-Control "max-age=31536000, public";
}
# Aggressive caching for static files
# If you alter static files often, please use
# add_header Cache-Control "max-age=31536000, public, must-revalidate, proxy-revalidate";
location ~* .(asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|eot|exe|gif|gz|gzip|ico|jpg|jpeg$
expires 31536000s;
access_log off;
log_not_found off;
add_header Pragma public;
add_header Cache-Control "max-age=31536000, public";
}
location ~* (^(?!(?:(?!(php|inc)).)*/uploads/).*?(php)) {
try_files $uri = 404;
fastcgi_split_path_info ^(.+.php)(.*)$;
fastcgi_pass unix:/var/run/php-fpm.socket;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
include /usr/local/apps/nginx/etc/fastcgi_params;
fastcgi_intercept_errors on;
fastcgi_ignore_client_abort off;
fastcgi_connect_timeout 60;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
}
}
and WebuzoVH.conf
code:
# DO NOT EDIT. AUTOMATICALLY GENERATED BY WEBUZO.
server {
listen 80;
server_name mydomain.com www.my domain.com;
# The Document Root
root /home/www-data/public_html;
error_log /usr/local/apps/nginx/var/log/mydomain.com.err;
access_log /usr/local/apps/nginx/var/log/mydomain.com.log main;
include /usr/local/apps/nginx/etc/conf.d/common;
}
what wrong here , how can I fix that ?
i sit on that almost 5 hours :-(
thanks for all who can help me,
Tomer.
i change to this setting and now Nginx give OK in Command
this what i changed..
maybe this can be help to other..
the nginx.conf file
#user www-data;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
pid /usr/local/apps/nginx/var/log/nginx.pid;
events {
worker_connections 1024;
multi_accept on;
use epoll;
}
http {
# Let NGINX get the real client IP for its access logs
set_real_ip_from 127.0.0.1;
real_ip_header X-Forwarded-For;
# Basic Settings
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 20;
client_max_body_size 15m;
client_body_timeout 60;
client_header_timeout 60;
client_body_buffer_size 1K;
client_header_buffer_size 1k;
large_client_header_buffers 4 8k;
send_timeout 60;
reset_timedout_connection on;
types_hash_max_size 2048;
server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /usr/local/apps/nginx/etc/mime.types;
default_type application/octet-stream;
# Logging Settings
#access_log /usr/local/apps/nginx/var/log/web.access.log;
error_log /usr/local/apps/nginx/var/log/error_log debug;
# Log Format
log_format main '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
# Gzip Settings
gzip on;
gzip_static on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_min_length 512;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/css text/javascript text/xml text/plain text/x-component
application/javascript application/x-javascript application/json
application/xml application/rss+xml font/truetype application/x-font-ttf
font/opentype application/vnd.ms-fontobject image/svg+xml
include /usr/local/apps/nginx/etc/conf.d/*.conf;
include /usr/local/apps/nginx/etc/sites-enabled/*;
}
and this for Mydomain.com.conf file
server {
listen 127.0.0.1:8080;
server_name mydomain.com;
port_in_redirect off;
server_tokens off;
autoindex off;
client_max_body_size 15m;
client_body_buffer_size 128k;
access_log /usr/local/apps/nginx/var/log/mydomian.com.log main;
error_log /usr/local/apps/nginx/var/log/mydomian.com.err;
root /home/www-data/public_html;
index index.php index.html index.htm;
try_files $uri $uri/ /index.php;
error_page 404 /404.html;
location = /404.html {
root /usr/local/apps/nginx/etc//html;
}
# Define default caching of 24h
expires 86400s;
add_header Pragma public;
add_header Cache-Control "max-age=86400, public, must-revalidate, proxy-revalidate";
# Redirect server error pages to static 50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/local/apps/nginx/etc//html;
}
# Don't log robots.txt requests
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
# Rewrite for versioned CSS+JS via filemtime
location ~* ^.+\.(css|js) {
rewrite ^(.+)\.(\d+)\.(css|js)$ $1.$3 last;
expires 31536000s;
access_log off;
log_not_found off;
add_header Pragma public;
add_header Cache-Control "max-age=31536000, public";
}
# Aggressive caching for static files
# If you alter static files often, please use
# add_header Cache-Control "max-age=31536000, public, must-revalidate, proxy-revalidate";
location ~* \.(asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|eot|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|mpp|odb|odc|odf|odg|odp|ods|odt|ogg|ogv|otf|pdf|png|pot|pps|ppt|pptx|ra|ram|svg|svgz|swf|tar|t?gz|tif|tiff|ttf|wav|webm|wma|woff|wri|xla|xls|xlsx|xlt|xlw|zip)$ {
expires 31536000s;
access_log off;
log_not_found off;
add_header Pragma public;
add_header Cache-Control "max-age=31536000, public";
}
location ~* (^(?!(?:(?!(php|inc)).)*/uploads/).*?(php)) {
try_files $uri = 404;
fastcgi_split_path_info ^(.+.php)(.*)$;
fastcgi_pass unix:/var/run/php-fpm.socket;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
include /usr/local/apps/nginx/etc/fastcgi_params;
fastcgi_intercept_errors on;
fastcgi_ignore_client_abort off;
fastcgi_connect_timeout 60;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
}
}
Somedays ago, on my server appeared error: video not found or access denied. The path are correct. I play video by jwplayer.
And i have a file protection from direct links.
location /route/ {
include /home/username/shop/route/route.conf;
}
in route.conf:
rewrite ^/route/9be25319f8164b5dacd481f700b3e69d/93/video.flv$ /media/courses/video1.flv;
Why it dont working?
full server config:
user nginx nginx;
worker_processes 3;
error_log /var/log/nginx/error_log info;
events {
worker_connections 1024;
use epoll;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main
'$remote_addr - $remote_user [$time_local] '
'"$request" $status $bytes_sent '
'"$http_referer" "$http_user_agent" '
'"$gzip_ratio"';
client_header_timeout 10m;
client_body_timeout 120m;
send_timeout 120m;
connection_pool_size 256;
client_header_buffer_size 1k;
large_client_header_buffers 4 2k;
request_pool_size 4k;
gzip off;
gzip_min_length 1100;
gzip_buffers 4 8k;
gzip_types text/plain;
output_buffers 1 32k;
postpone_output 1460;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 75 20;
ignore_invalid_headers on;
index index.html;
server {
listen X.X.X.X:80;
server_name mysite.com;
access_log /home/user/logs/nginx-access.log;
error_log /home/user/logs/nginx-error.log;
location /static/ {
alias /home/user/shop/static/;
}
location /media/ {
alias /home/user/shop/media/;
}
location /route/ {
include /home/shamprod/shop/route/route.conf;
}
location / {
proxy_pass http://127.0.0.1:8888/;
include /etc/nginx/proxy.conf;
}
}
I am unable to run .html files on my Ubuntu 12.04 server running with Nginx and php-fpm.
What I get is Access denied, when executing .html extension files. .php files runs very well.
Here is my config code.
nginx.conf
user www-data;
worker_processes 4; # Make this equal to no of processors you have "cat /proc/cpuinfo |grep processor" #mayur
pid /var/run/nginx.pid;
events {
worker_connections 2048; # Essential to keep it high for heavy sites #mayur
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
server_tokens on; #Make this off Live Server for Security Reasons: #mayur
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
log_format main '$remote_addr - $remote_user [$time_local] $request '
'"$status" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
##
# nginx-naxsi config
##
# Uncomment it if you installed nginx-naxsi
##
#include /etc/nginx/naxsi_core.rules;
##
# nginx-passenger config
##
# Uncomment it if you installed nginx-passenger
##
#passenger_root /usr;
#passenger_ruby /usr/bin/ruby;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
sites-available/default
server {
listen 80; ## listen for ipv4; this line is default and implied
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
root /data/paytm/htdocs;
index index.php index.html;
server_name localhost;
ssi on;
location ~* ^.+\.(jpg|js|jpeg|png|ico|gif|js|css|swf)$ {
expires 24h;
}
location ~ ^/.*\.html$ {
fastcgi_pass unix:/tmp/php5-fpm.sock;
fastcgi_index index.html;
fastcgi_param SCRIPT_FILENAME /data/paytm/htdocs/$fastcgi_script_name;
include fastcgi_params;
}
location ~ ^/.*\.php$ {
fastcgi_pass unix:/tmp/php5-fpm.sock;
fastcgi_index index.html;
fastcgi_param SCRIPT_FILENAME /data/paytm/htdocs/$fastcgi_script_name;
include fastcgi_params;
}
# For APIs and other stuff where we write our own Header Variables
underscores_in_headers on;
ignore_invalid_headers off;
}
See here : https://bugs.php.net/bug.php?id=60763 You need to add to the /etc/php5/fpm/pool.d/www.conf inside the [www] section
security.limit_extensions = .php .html
Please remove the location ~ ^/.*\.html$ section in sites-available/default.