Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
Firstly, nginx should listen on port 80 (only external ip is allowed), and apache on another one, for example 81 (only ip 127.0.0.1 is allowed).
Further, for everything to work well - both in nginx and in apache, the same sites must be configured separately - this way there will be no confusion, and it will be possible to make changes to the settings for each site separately.
Accordingly, the settings:
Move all reverse-proxy nginx settings to a separate file:
>>> /etc/nginx/proxy.conf >>>
# настройка проксирования
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;
# настройка кеширования
proxy_cache_key "$scheme://$host$request_uri $do_not_cache";
proxy_cache cache;
proxy_cache_valid 200 302 60m;
proxy_cache_valid 404 1m;
server {
listen 123.123.123.123:80;
server_name www.site1.ru site1.ru;
access_log /var/log/nginx/site1.ru_nginx_access_log;
error_log /var/log/nginx/site1.ru_nginx_error_log;
location / {
include /etc/nginx/proxy.conf;
proxy_pass http://site1.ru:81;
}
#Статику отдаём напрямик
location ~* ^.+\.(jpe?g|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mp3)$ {
expires 30d;
root /home/site1.ru/public_html;}
# Запрещаем открытие .htaccess через браузер
location ~ /\.ht {deny all;}
}
server {
listen 123.123.123.123:80;
server_name www.site2.ru site2.ru;
access_log /var/log/nginx/site2.ru_nginx_access_log;
error_log /var/log/nginx/site2.ru_nginx_error_log;
location / {
include /etc/nginx/proxy.conf;
proxy_pass http://site2.ru:81;
}
#Статику отдаём напрямик
location ~* ^.+\.(jpe?g|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mp3)$ {
expires 30d;
root /home/site2.ru/public_html;}
# Запрещаем открытие .htaccess через браузер
location ~ /\.ht {deny all;}
}
<VirtualHost 127.0.0.1:81>
ServerName site1.ru
ServerAlias www.site1.ru
DocumentRoot /home/site1.ru/public_html
...
</VirtualHost>
<VirtualHost 127.0.0.1:81>
ServerName site2.ru
ServerAlias www.site2.ru
DocumentRoot /home/site2.ru/public_html
...
</VirtualHost>
Sorry for the inaccurate question
server {
listen 80;
server_name site3
location /site1 {
proxy_pass http://site1:88;
proxy_redirect off;
proxy_intercept_errors on;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
server {
listen 80;
server_name site4
location /site2 {
proxy_pass http://site2:88;
proxy_redirect off;
proxy_intercept_errors on;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
In this version does not work
If nginx is the front and apache is the back, then what's the point of nginx distinguishing which site the request goes to? It should redirect all requests to apache, and that, in turn, should give the desired content.
Let me explain the question again
Nginx is the frontend, Apache is the backend. In the nginx config, you need to register two virtual hosts site3 and site4. What would site3 on the backend give out site1, and site4 give out site2.
Thanks for the answer. in principle, I realized that it is better to make such sites with the same names
upstream backend {
server 127.0.0.1:8080;
}
server {
listen 80;
server_name 12.23.34.45; /* внешний ip-адрес сервера */
location / {
proxy_pass http://backend/;
proxy_redirect off;
proxy_intercept_errors on;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
location ~ /\.ht {
deny all;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question