📜 ⬆️ ⬇️

We do nginx as front-end to apache

This topic is quite beaten, but on the Internet it is not so easy to find a short and clear answer to this question. That's why I decided to collect everything in the form of a small instruction.

First, let's look at the logic of work. Everything is very simple: static files are given by nginx, and apache is engaged in dynamics (see diagram)

image

This example is implemented on Ubuntu Server 10.04
')
Step one: install Apache, PHP, MySQL and nginx


Install apache
apt-get install apache2
[+ mod_rewrite]
a2enmod rewrite

PHP installation
apt-get install php5-cli

MySQL installation
apt-get install mysql-server
apt-get install mysql-client-core-5.1
apt-get install php5-mysql

Install nginx
apt-get install nginx
Configs -> / etc / nginx

Step Two

We hang apache on port 8080 (or on the other, except 80)
We make changes to the Apache configuration:
/etc/apache2/ports.conf
NameVirtualHost *: 8080
Listen 8080
If there are virtual hosts, then they also need to hang on port 8080

Step Three

We configure nginx
Create a configuration file in the directory: / etc / nginx / sites-available
server {
listen *:80; ## listen for ipv4
server_name _;
access_log /var/log/nginx/access.log;
# back-end
location / {
proxy_pass _:8080/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_connect_timeout 120;
proxy_send_timeout 120;
proxy_read_timeout 180;
}
# nginx
# back-end
location ~* \.(jpg|jpeg|gif|png|ico|css|bmp|swf|js|html|txt)$ {
root ____;
}
}

Step Four

Restart apache and nginx:
/etc/init.d/apache2 restart
/etc/init.d/nginx restart

Source: https://habr.com/ru/post/120814/


All Articles