nginx 414 Request-URI Too Long - nginx

when I open 127.0.0.1, the url would jump to 127.0.0.1/k.com/k.com/k/.com/......
my hosts
127.0.0.1 localhost
127.0.0.1 k.com
my nginx config
#user _www;
worker_processes 1;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
access_log off;
gzip off;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain application/json application/x-javascript text/css application/xml text/javascript;
gzip_vary on;
gzip_disable "MSIE [1-6]\.";
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name k.com;
client_max_body_size 20M;
root F:/xxxx/www;
underscores_in_headers on;
index index.html;
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET,POST,PUT,DELETE';
add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,username,password,remember,token';
location / {
try_files $uri $uri/ /index.html;
}
location = /index.html {
add_header Cache-Control no-cache;
add_header Cache-Control private;
}
}
server {
listen 80;
server_name localhost;
root F:/xxxx/www/htdocs; #
index index.html index.php;
autoindex on;
location / {
try_files $uri $uri/ /index.html;
}
}
}
how to configure 127.0.0.1 , direct to another directory or empty page, either or direct to localhost.

Related

Nginx location regex configuration issue - Not capturing subdomains of location specified

I am using below nginx file. I have hosted multiple frontend (angular) projects on single server. So, I want to access different project on different path.
When I hit url www.*********.com/st_admit/dashboard
I want to access project place in directory /usr/share/nginx/html2; but nginx is redirecting to root domain i.e. "/" and open the project placed in /usr/share/nginx/html;
Please check below configuration file and let me know how I can fix the nginx location regex.
client_max_body_size 10M;
upstream django {
ip_hash;
server django_gunicorn:8001;
}
server {
server_name *************.*** www.******.***;
listen 443 ssl;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload";
ssl_certificate /etc/nginx/***********.crt;
ssl_certificate_key /etc/nginx/*************.key;
client_max_body_size 4G;
proxy_read_timeout 20000;
proxy_connect_timeout 20000;
proxy_send_timeout 20000;
keepalive_timeout 200;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
server_tokens off;
ssl_protocols TLSv1.2 TLSv1.3;
root /usr/share/nginx/html;
location ^~ /st_admin/(.*) {
alias /usr/share/nginx/html2;
index index.html index.htm;
include /etc/nginx/mime.types;
gzip on;
gzip_min_length 1000;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;
try_files $uri $uri/ /index.html;
}
location /api/ {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header Host $http_host;
proxy_redirect off;
if (!-f $request_filename) {
proxy_pass http://django;
break;
}
}
location / {
root /usr/share/nginx/html;
index index.html index.htm;
include /etc/nginx/mime.types;
gzip on;
gzip_min_length 1000;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;
try_files $uri $uri/ /index.html;
}
}
I tried below location configurations, but none of these are working.
location ^~ /st_admin
location ^~ /st_admin/*
location ^~ /st_admin/(.*)

nginx: nginx: [emerg] "upstream" directive is not allowed here in /etc/nginx/sites-enabled/www.example.com.conf

Please, can anyone help me? I'm having to do a load balance on a reverse proxy server, which was not configured by me.
And when I configure the upstream directive it is giving an error. I have already tried to set it within http {} and within the settings of the site included.
My nginx.conf
load_module /usr/lib64/nginx/modules/ngx_stream_module.so;
user nginx;
worker_processes 16;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
events {
worker_connections 1024;
}
http {
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;
client_max_body_size 20m;
proxy_read_timeout 3600;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Security #
add_header Strict-Transport-Security "max-age=63072000; includeSubdomains";
ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH";
keepalive_timeout 750;
server_tokens off;
#more_clear_headers 'Server' 'X-Powered-By' 'X-Content-Powered-By';
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
add_header X-Content-Type-Options nosniff;
add_header Content-Security-Policy "frame-ancestors digital.fortaleza.ce.gov.br epgm.pgm.fortaleza.ce.gov.br revista.pgm.fortaleza.ce.gov.br";
add_header X-Frame-Options "ALLOW-FROM digital.fortaleza.ce.gov.br epgm.pgm.fortaleza.ce.gov.br";
add_header X-Frame-Options SAMEORIGIN;
add_header X-XSS-Protection "1; mode=block";
#Compression
gzip on;
gzip_proxied any;
gzip_vary on;
gzip_disable “MSIE [1-6]\.(?!.*SV1)”;
gzip_disable "msie6";
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;
#SSl Certificate Security
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_dhparam /etc/nginx/ssl/dhparam4096.pem;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
#Proxy
proxy_hide_header on;
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 $host;
proxy_set_header X-Forwarded-Server $host;
server {
listen 80;
error_page 404 /404.html;
location = /basic_status {
stub_status;
allow 172.30.50.100;
allow 10.0.10.100;
deny all;
}
location / {
return 301 https://www.example.com.br;
}
}
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*.conf;
}
My www.example.com.br config file inside sites-enable
upstream example {
server 192.168.0.1;
server 192.168.0.2;
}
server {
listen 443 ssl;
server_name www.example.com.br;
ssl_certificate /etc/nginx/certificates/bundle-pgm.crt;
ssl_certificate_key /etc/nginx/certificates/privatekey.key;
access_log /var/log/nginx/www.example.com.br/www.example.com.br_access.log;
error_log /var/log/nginx/www.example.com.br/www.example.com.br error;
location / {
proxy_pass http://example;
}
}
server {
if ($host = www.example.com.br) {
return 301 https://$host$request_uri;
}
listen 80;
server_name www.example.com.br;
return 404;
}

NGINX suddenty stops proxying requests

I have an NGINX server set up to serve static content. Moreover, this NGINX proxies requests coming from bots to a pre-rendering service. Suddenly, and for no apparent reason at all, NGINX stops redirecting these requests to the service. Instead, NGINX keeps on responding with 504 timeouts. I do not understand why it happens abruptly (instead of regularly), and the reasons behind it. I analyzed the request logs, and could not find a pattern.
I have NGINX v1.10.3 running on Ubuntu 16.04 machine.
Below is the configuration files for NGINX:
nginx.conf:
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
client_max_body_size 20M;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
proxy_connect_timeout 10s;
proxy_send_timeout 10s;
proxy_read_timeout 10s;
send_timeout 10s;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
real_ip_header X-Forwarded-For;
set_real_ip_from 10.0.0.0/8;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
log_format main '"$time_local" client=$remote_addr '
'method=$request_method request="$request" '
'request_length=$request_length '
'status=$status bytes_sent=$bytes_sent '
'body_bytes_sent=$body_bytes_sent '
'referer=$http_referer '
'user_agent="$http_user_agent" '
'upstream_addr=$upstream_addr '
'upstream_status=$upstream_status '
'request_time=$request_time '
'upstream_response_time=$upstream_response_time '
'upstream_connect_time=$upstream_connect_time '
'upstream_header_time=$upstream_header_time';
access_log /var/log/nginx/access.log main;
error_log /var/log/nginx/error.log;
##
# 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/javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
virtual server:
server {
listen 443 ssl http2;
server_name serverName.com;
ssl on;
ssl_certificate <crtLocation>;
ssl_certificate_key <keyLocation>;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
add_header 'Access-Control-Allow-Origin' "$http_origin" always;
add_header 'Access-Control-Allow-Credentials' 'true' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
add_header 'Access-Control-Allow-Headers' 'Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Requested-With' always;
client_body_timeout 7s;
client_header_timeout 7s;
location / {
set $prerender 0;
if ($http_user_agent ~* "Google|Googlebot|Googlebot\-News|Googlebot\-Image|Googlebot\-Video|Mediapartners\-Google|AdsBot\-Google|Bingbot|MSNBot|MSNBot\-Media|AdIdxBot|BingPreview|Slurp|DuckDuckBot|Baiduspider|Baiduspider|Baiduspider|Yandexbot|facebookexternalhit|FacebookExternalHit|Facebot|Twitterbot|LinkedInBot|rogerbot|DotBot|MJ12bot|AhrefsBot|ia\_archiver|embedly|quora\ link\ preview|showyoubot|outbrain|pinterest|slackbot|vkShare|W3C_Validator"){
set $prerender 1;
}
if ($args ~ "_escaped_fragment_") {
set $prerender 1;
}
if ($http_user_agent ~ "Prerender") {
set $prerender 0;
}
if ($uri ~* "\.(js|css|xml|less|png|jpg|jpeg|gif|pdf|doc|txt|ico|rss|zip|mp3|rar|exe|wmv|doc|avi|ppt|mpg|mpeg|tif|wav|mov|psd|ai|xls|mp4|m4a|swf|dat|dmg|iso|flv|m4v|torrent|ttf|woff|svg|eot)"){
set $prerender 0;
}
if ($prerender = 1) {
rewrite .* /$scheme://$host$request_uri? break;
proxy_pass <proxy server>;
}
try_files $uri $uri/ /index.php;
}
location ~ .php/ { ## Forward paths like /js/index.php/x.js to relevant handler
rewrite ^(.*.php)/ $1 last;
}
location ~ \.php$ {
include fastcgi.conf;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
try_files $uri =404;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
}
}

Http not redirecting to https nginx

I have set up letsEncrypt free ssl with certbot on ubuntu 14.04 from digitalocean tutorial.
If anyone tries to access the page on 80 ( http://gw2axiom.com ) , it shows 404 not found.
If you try https://gw2axiom.com it will work normally. After that, http will redirect to 443.
What could be the reason?
My nginx config file is the following :
# FORGE CONFIG (DOT NOT REMOVE!)
include forge-conf/gw2axiom.com/before/*;
server {
listen 443 ssl;
server_name gw2axiom.com www.gw2axiom.com;
root /home/forge/gw2axiom.com/public;
ssl_certificate /etc/letsencrypt/live/gw2axiom.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/gw2axiom.com/privkey.pem;
# FORGE SSL (DO NOT REMOVE!)
# ssl_certificate;
# ssl_certificate_key;
location /forum/ { try_files $uri $uri/ /forum/index.php?$query_string; }
location /forum/api { try_files $uri $uri/ /forum/api.php?$query_string; }
location ~ /.well-known {
allow all;
}
location /forum/admin { try_files $uri $uri/ /forum/admin.php?$query_string; }
location /flarum {
deny all;
return 404;
}
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_dhparam /etc/ssl/certs/dhparam.pem;
ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA';
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:50m;
ssl_stapling on;
ssl_stapling_verify on;
add_header Strict-Transport-Security max-age=15768000;
index index.html index.htm index.php;
charset utf-8;
# FORGE CONFIG (DOT NOT REMOVE!)
include forge-conf/gw2axiom.com/server/*;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log /var/log/nginx/gw2axiom.com-error.log error;
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index index.php;
include fastcgi_params;
}
location ~* \.html$ {
expires -1;
}
location ~* \.(css|js|gif|jpe?g|png)$ {
expires 1M;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}
gzip on;
gzip_http_version 1.1;
gzip_vary on;
gzip_comp_level 6;
gzip_proxied any;
gzip_types application/atom+xml
application/javascript
application/json
application/vnd.ms-fontobject
application/x-font-ttf
application/x-web-app-manifest+json
application/xhtml+xml
application/xml
font/opentype
image/svg+xml
image/x-icon
text/css
text/plain
text/xml;
gzip_buffers 16 8k;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
location ~ /\.ht {
deny all;
}
}
server {
listen 80;
server_name www.gw2axiom.com gw2axiom.com;
return 301 https://$server_name$request_uri;
}
# FORGE CONFIG (DOT NOT REMOVE!)
include forge-conf/gw2axiom.com/after/*;
Put this before your current server entry:
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name gw2axiom.com;
return 301 https://$server_name$request_uri;
}
After that restart your nginx webserver and everything should work fine.

"server" directive is not allowed here in /usr/local/apps/nginx/etc/conf.d/, what i did wrong here ? (0 Replies, Read 16 times)

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;
}
}

Resources