Welcome! Log In Create A New Profile

Advanced

nginx vhost cannot add subdomain

Posted by krzysztof86 
nginx vhost cannot add subdomain
September 24, 2012 02:15AM
Hello. I have verry strange errors. Cant run on one server 2 the same applications in diverencent folders. When i sometime change something, there both run but when i write in browser: xxxxxxxx.xx/start there displaying me test application not production - not what i want. When i write test.xxxxxxx.xx there displaying me test application. I dont have idea what is wrong with my configuration. Both apps run on Symfony 2 framework.
I be glad if some expert look at this and show me the right solution.




I redirect A records from xxxxxxxx.xx to 9.9.99.999
A record from *.xxxxxxxx.xx to 9.9.99.999
A record from test.xxxxxxx.xx to 9.9.99.999


/etc/hosts
9.99.99.999 www.xxxxxxxx.xx
9.9.99.999 xxxxxxxx.xx
9.9.99.999 test.xxxxxxxxx.xx
9.9.99.999 www.test.xxxxxxxx.xx




default (this is production aplication)

server {
listen 80;

server_name *.dev *.xxxxxxxx.xx xxxxxxxx.xx;
root /var/www/xxxxxxx.xx/web;

access_log /var/log/nginx/$host.access.log;
error_log /var/log/nginx/error.log error;

# strip app.php/ prefix if it is present
rewrite ^/app\.php/?(.*)$ /$1 permanent;

location / {
root /var/www/xxxxxxxx.xx/web/;
index app.php;
try_files $uri @rewriteapp;
}

location @rewriteapp {
rewrite ^(.*)$ /app.php/$1 last;
}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ ^/(app|app_dev)\.php(/|$) {
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
}

location ~ \.php {
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}

location ~ /\.ht {
deny all;
}

## DODATKI

## boty
if ($http_user_agent ~* (HTTrack|HTMLParser|libcurl|discobot|Exabot|Casper|kmccrew|plaNETWORK|RPT-HTTPClient)) {
return 444;
}

## boty
if ($http_referer ~* (sex|vigra|viagra) ) {
return 444;
}

## Favicon Not Found
location = /favicon.ico {
access_log off;
log_not_found off;
}

## Robots.txt Not Found
location = /robots.txt {
access_log off;
log_not_found off;
}

if ($host !~* ^www\.) {
rewrite ^(.*)$ http://www.$host$1 permanent;
}

if ($request_uri = "/login") {
rewrite ^ https://$host$request_uri permanent;
break;
}


if ($request_uri = "/register") {
rewrite ^ https://$host$request_uri permanent;
break;
}


}



# HTTPS server

server {
listen 443;
server_name xxxxxxxx.xx;
root /var/www/xxxxxxx.xx/web;

ssl on;
ssl_certificate /etc/nginx/ssl/slubnaglowie.pem;
ssl_certificate_key /etc/nginx/ssl/slubnaglowie.key;
ssl_protocols TLSv1;
ssl_prefer_server_ciphers on;
ssl_ciphers RC4-SHA:HIGH:!kEDH;



rewrite ^/app\.php/?(.*)$ /$1 permanent;

location / {
root /var/www/xxxxxxx.xx/web/;
index app.php;
try_files $uri @rewriteapp;
}

location @rewriteapp {
rewrite ^(.*)$ /app.php/$1 last;
}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ ^/(app|app_dev)\.php(/|$) {
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS on;
}

## DODATKI

## boty
if ($http_user_agent ~* (HTTrack|HTMLParser|libcurl|discobot|Exabot|Casper|kmccrew|plaNETWORK|RPT-HTTPClient)) {
return 444;
}

## boty
if ($http_referer ~* (sex|vigra|viagra) ) {
return 444;
}

## Favicon Not Found
location = /favicon.ico {
access_log off;
log_not_found off;
}

## Robots.txt Not Found
location = /robots.txt {
access_log off;
log_not_found off;
}


}








test ( test application)

server {
listen 80;

server_name test.xxxxxxxxxxx.xx;
root /var/www/testowa/web;

access_log /var/log/nginx/$host.access.log;
error_log /var/log/nginx/error.log error;

# strip app.php/ prefix if it is present
rewrite ^/app\.php/?(.*)$ /$1 permanent;

location / {
root /var/www/testowa/web/;
index app.php;
try_files $uri @rewriteapp;
}

location @rewriteapp {
rewrite ^(.*)$ /app.php/$1 last;
}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ ^/(app|app_dev)\.php(/|$) {
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
}

location ~ \.php {
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}

location ~ /\.ht {
deny all;
}

## DODATKI

## boty
if ($http_user_agent ~* (HTTrack|HTMLParser|libcurl|discobot|Exabot|Casper|kmccrew|plaNETWORK|RPT-HTTPClient)) {
return 444;
}

## boty
if ($http_referer ~* (sex|vigra|viagra) ) {
return 444;
}

## Favicon Not Found
location = /favicon.ico {
access_log off;
log_not_found off;
}

## Robots.txt Not Found
location = /robots.txt {
access_log off;
log_not_found off;
}

if ($host !~* ^www\.) {
rewrite ^(.*)$ http://www.$host$1 permanent;
}

if ($request_uri = "/login") {
rewrite ^ https://$host$request_uri permanent;
break;
}


if ($request_uri = "/register") {
rewrite ^ https://$host$request_uri permanent;
break;
}

#===extra security
## Block SQL injections
set $block_sql_injections 0;
if ($query_string ~ "union.*select.*\(") {
set $block_sql_injections 1;
}
if ($query_string ~ "union.*all.*select.*") {
set $block_sql_injections 1;
}
if ($query_string ~ "concat.*\(") {
set $block_sql_injections 1;
}
if ($block_sql_injections = 1) {
return 403;
}

## Block file injections
set $block_file_injections 0;
if ($query_string ~ "[a-zA-Z0-9_]=http://") {
set $block_file_injections 1;
}
if ($query_string ~ "[a-zA-Z0-9_]=(\.\.//?)+") {
set $block_file_injections 1;
}
if ($query_string ~ "[a-zA-Z0-9_]=/([a-z0-9_.]//?)+") {
set $block_file_injections 1;
}
if ($block_file_injections = 1) {
return 403;
}

## Block common exploits
set $block_common_exploits 0;
if ($query_string ~ "(<|%3C).*script.*(>|%3E)") {
set $block_common_exploits 1;
}
if ($query_string ~ "GLOBALS(=|\[|\%[0-9A-Z]{0,2})") {
set $block_common_exploits 1;
}
if ($query_string ~ "_REQUEST(=|\[|\%[0-9A-Z]{0,2})") {
set $block_common_exploits 1;
}
if ($query_string ~ "proc/self/environ") {
set $block_common_exploits 1;
}
if ($query_string ~ "mosConfig_[a-zA-Z_]{1,21}(=|\%3D)") {
set $block_common_exploits 1;
}
if ($query_string ~ "base64_(en|de)code\(.*\)") {
set $block_common_exploits 1;
}
if ($block_common_exploits = 1) {
return 403;
}

## Block spam
set $block_spam 0;
if ($query_string ~ "\b(ultram|unicauca|valium|viagra|vicodin|xanax|ypxaieo)\b") {
set $block_spam 1;
}
if ($query_string ~ "\b(erections|hoodia|huronriveracres|impotence|levitra|libido)\b") {
set $block_spam 1;
}
if ($query_string ~ "\b(ambien|blue\spill|cialis|cocaine|ejaculation|erectile)\b") {
set $block_spam 1;
}
if ($query_string ~ "\b(lipitor|phentermin|pro[sz]ac|sandyauer|tramadol|troyhamby)\b") {
set $block_spam 1;
}
if ($block_spam = 1) {
return 403;
}

## Block user agents
set $block_user_agents 0;

# Don't disable wget if you need it to run cron jobs!
#if ($http_user_agent ~ "Wget") {
# set $block_user_agents 1;
#}

# Disable Akeeba Remote Control 2.5 and earlier
if ($http_user_agent ~ "Indy Library") {
set $block_user_agents 1;
}

# Common bandwidth hoggers and hacking tools.
if ($http_user_agent ~ "libwww-perl") {
set $block_user_agents 1;
}
if ($http_user_agent ~ "GetRight") {
set $block_user_agents 1;
}
if ($http_user_agent ~ "GetWeb!") {
set $block_user_agents 1;
}
if ($http_user_agent ~ "Go!Zilla") {
set $block_user_agents 1;
}
if ($http_user_agent ~ "Download Demon") {
set $block_user_agents 1;
}
if ($http_user_agent ~ "Go-Ahead-Got-It") {
set $block_user_agents 1;
}
if ($http_user_agent ~ "TurnitinBot") {
set $block_user_agents 1;
}
if ($http_user_agent ~ "GrabNet") {
set $block_user_agents 1;
}

if ($block_user_agents = 1) {
return 403;
}


}



# HTTPS server

server {
listen 443;
server_name test.xxxxxxxxxx.xx;
root /var/www/testowa/web;

ssl on;
ssl_certificate /etc/nginx/ssl/xxxxx.pem;
ssl_certificate_key /etc/nginx/ssl/xxxxx.key;
ssl_protocols TLSv1;
ssl_prefer_server_ciphers on;
ssl_ciphers RC4-SHA:HIGH:!kEDH;



rewrite ^/app\.php/?(.*)$ /$1 permanent;

location / {
root /var/www/testowa/web/;
index app.php;
try_files $uri @rewriteapp;
}

location @rewriteapp {
rewrite ^(.*)$ /app.php/$1 last;
}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ ^/(app|app_dev)\.php(/|$) {
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS on;
}

## DODATKI

## boty
if ($http_user_agent ~* (HTTrack|HTMLParser|libcurl|discobot|Exabot|Casper|kmccrew|plaNETWORK|RPT-HTTPClient)) {
return 444;
}

## boty
if ($http_referer ~* (sex|vigra|viagra) ) {
return 444;
}

## Favicon Not Found
location = /favicon.ico {
access_log off;
log_not_found off;
}

## Robots.txt Not Found
location = /robots.txt {
access_log off;
log_not_found off;
}


#================extra security

## Block SQL injections
set $block_sql_injections 0;
if ($query_string ~ "union.*select.*\(") {
set $block_sql_injections 1;
}
if ($query_string ~ "union.*all.*select.*") {
set $block_sql_injections 1;
}
if ($query_string ~ "concat.*\(") {
set $block_sql_injections 1;
}
if ($block_sql_injections = 1) {
return 403;
}

## Block file injections
set $block_file_injections 0;
if ($query_string ~ "[a-zA-Z0-9_]=http://") {
set $block_file_injections 1;
}
if ($query_string ~ "[a-zA-Z0-9_]=(\.\.//?)+") {
set $block_file_injections 1;
}
if ($query_string ~ "[a-zA-Z0-9_]=/([a-z0-9_.]//?)+") {
set $block_file_injections 1;
}
if ($block_file_injections = 1) {
return 403;
}

## Block common exploits
set $block_common_exploits 0;
if ($query_string ~ "(<|%3C).*script.*(>|%3E)") {
set $block_common_exploits 1;
}
if ($query_string ~ "GLOBALS(=|\[|\%[0-9A-Z]{0,2})") {
set $block_common_exploits 1;
}
if ($query_string ~ "_REQUEST(=|\[|\%[0-9A-Z]{0,2})") {
set $block_common_exploits 1;
}
if ($query_string ~ "proc/self/environ") {
set $block_common_exploits 1;
}
if ($query_string ~ "mosConfig_[a-zA-Z_]{1,21}(=|\%3D)") {
set $block_common_exploits 1;
}
if ($query_string ~ "base64_(en|de)code\(.*\)") {
set $block_common_exploits 1;
}
if ($block_common_exploits = 1) {
return 403;
}

## Block spam
set $block_spam 0;
if ($query_string ~ "\b(ultram|unicauca|valium|viagra|vicodin|xanax|ypxaieo)\b") {
set $block_spam 1;
}
if ($query_string ~ "\b(erections|hoodia|huronriveracres|impotence|levitra|libido)\b") {
set $block_spam 1;
}
if ($query_string ~ "\b(ambien|blue\spill|cialis|cocaine|ejaculation|erectile)\b") {
set $block_spam 1;
}
if ($query_string ~ "\b(lipitor|phentermin|pro[sz]ac|sandyauer|tramadol|troyhamby)\b") {
set $block_spam 1;
}
if ($block_spam = 1) {
return 403;
}

## Block user agents
set $block_user_agents 0;

# Don't disable wget if you need it to run cron jobs!
#if ($http_user_agent ~ "Wget") {
# set $block_user_agents 1;
#}

# Disable Akeeba Remote Control 2.5 and earlier
if ($http_user_agent ~ "Indy Library") {
set $block_user_agents 1;
}

# Common bandwidth hoggers and hacking tools.
if ($http_user_agent ~ "libwww-perl") {
set $block_user_agents 1;
}
if ($http_user_agent ~ "GetRight") {
set $block_user_agents 1;
}
if ($http_user_agent ~ "GetWeb!") {
set $block_user_agents 1;
}
if ($http_user_agent ~ "Go!Zilla") {
set $block_user_agents 1;
}
if ($http_user_agent ~ "Download Demon") {
set $block_user_agents 1;
}
if ($http_user_agent ~ "Go-Ahead-Got-It") {
set $block_user_agents 1;
}
if ($http_user_agent ~ "TurnitinBot") {
set $block_user_agents 1;
}
if ($http_user_agent ~ "GrabNet") {
set $block_user_agents 1;
}

if ($block_user_agents = 1) {
return 403;
}




}
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 208
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready