Configurare nginx ca front-end proxy pentru apache

Configurare noua (How To)

Situatie

Instalare & Configurare nginx

Solutie

 

Instalam nginx:

Code:
apt-get install nginx

Configurare:

Facem un fisier de configuratie (ex, mai jos)

Code:
nano /etc/nginx/sites-available/example

cu urmatoarea configuratie:

Code:
#fisier configuratie nginx
server {
        listen   80; 

        root /var/www/;  #calea default apache2
        index index.php index.html index.htm; 

        server_name example.com; 

        location / {
        try_files $uri $uri/ /index.php;
        }

        location ~ .php$ {
        
        proxy_set_header X-Real-IP  $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Host $host;
        proxy_pass http://127.0.0.1:8080;

         }

         location ~ /.ht {
                deny all;
        }
}

Am modificat calea “radacina” unde sunt fisierele “web”, index.php sa fie by default cand intri pe server (index), try_files, proxy_pass, si nimeni sa nu aiba access la fisierele .htaccess

Configuratia redirectioneaza toate extensile php pe apache backend.

Facem symlink la config

Code:
ln -s /etc/nginx/sites-available/example /etc/nginx/sites-enabled/example

stergem fisierul default nginx

Code:
rm /etc/nginx/sites-enabled/default

Instalare & configurare apache + instalare php5

Code:
apt-get install apache2

listam pe 8080 sa fie backend

[code]echo “Listen 127.0.0.1:8080” > /etc/apache2/ports.conf

editam configuratia de la vhost

Code:
nano /etc/apache2/sites-available/example

modificarile ar trebui sa arate cam asa:

Code:
<VirtualHost 127.0.0.1:8080>

Activam virtualhostul

Code:
a2ensite example

+ instalam php5

Code:
apt-get install php5

restartam serviciile

Code:
service apache2 restart
Code:
service nginx restart

Tip solutie

Permanent

Voteaza

(41 din 76 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?