Answer the question
In order to leave comments, you need to log in
Bundle nginx (FE) + apache (BE) for multiple domains?
There was a following problem.
There are two domains. One of which is used with subdomains.
example:
First domain: domain1.ru with subdomains sub.domen1.ru, sub2.domain.ru
Second domain: domain2.ru
So, for the first domain and its subdomains, all traffic is proxied and everything works as it should. However, for the second domain, nginx refuses to process any directives and throws out the default site.
vhost from apache will not spread, it makes no sense, it does not come to it.
The nginx config is the following:
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 512;
sendfile on;
keepalive_timeout 0;
server {
listen 80 default;
server_name _;
access_log off;
error_log off;
return 444;
}
server {
listen 80;
server_name domain1.ru www.domain1.ru;
charset utf-8;
keepalive_timeout 65;
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript;
location / {
proxy_pass http://127.0.0.1:9999;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 1s;
proxy_send_timeout 10s;
proxy_intercept_errors off;
proxy_buffer_size 4k;
proxy_buffers 8 64k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 10m;
proxy_read_timeout 120s;
}
location ~* \.(jpg|jpeg|gif|png|bmp|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|js|swf|mp3|woff)$ {
root C:/WEB/Apache24/htdocs/domain1.ru;
expires 168h;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}
location ~ /\.ht { deny all; }
error_page 500 /500.html;
location = /500.html {
root C:/WEB/Apache24/htdocs/error_pages;
}
error_page 502 /502.html;
location = /502.html {
root C:/WEB/Apache24/htdocs/error_pages;
}
error_page 503 /503.html;
location = /503.html {
root C:/WEB/Apache24/htdocs/error_pages;
}
error_page 504 /504.html;
location = /504.html {
root C:/WEB/Apache24/htdocs/error_pages;
}
}
server {
listen 80;
server_name sub.domain1.ru;
charset utf-8;
location / {
proxy_pass http://127.0.0.1:9999;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 1s;
proxy_send_timeout 10s;
proxy_intercept_errors off;
proxy_buffer_size 4k;
proxy_buffers 8 64k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 10m;
proxy_read_timeout 120s;
}
location ~* \.(jpg|jpeg|gif|png|bmp|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|js|swf|mp3|woff)$ {
root C:/WEB/Apache24/htdocs/sub.domain1.ru;
expires 168h;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}
location ~ /\.ht { deny all; }
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 80;
server_name www.domain2.ru domain2.ru;
charset utf-8;
access_log C:/WEB/nginx/logs/domain2.ru_access.log;
error_log C:/WEB/nginx/logs/domain2.ru_error.log;
location / {
proxy_pass http://127.0.0.1:9999;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 1s;
proxy_send_timeout 10s;
proxy_intercept_errors off;
proxy_temp_file_write_size 10m;
proxy_read_timeout 900s;
proxy_buffering off;
}
location ~* \.(jpg|jpeg|gif|png|bmp|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|js|swf|mp3|woff)$ {
root C:/WEB/Apache24/htdocs/domain2.ru;
expires 168h;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}
location ~ /\.ht { deny all; }
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
Answer the question
In order to leave comments, you need to log in
For www.domain2.ru domain2.ru; specify proxypass 127.0.0.1:9998 and apache port 9998
Thank you! In general, it helped, but apache does not respond on port 9998.
apache config:
<VirtualHost *:9998>
ServerAdmin [email protected]
DocumentRoot "C:/WEB/Apache24/htdocs/domain2.ru"
ServerName domain2.ru
ErrorLog "logs/domain2.ru-error.log"
CustomLog "logs/domain2.ru-access.log" common
</VirtualHost>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question