S
S
svd712014-01-10 11:57:05
ubuntu
svd71, 2014-01-10 11:57:05

Setting up nginx(proxy) + apache with url rewrite?

server {
        listen   80; 

        root /var/www/; 
        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;
        }
}

the location section is especially confusing.
1. But judging by the configuration script, problems may arise when apache rewrite is enabled from .htaccess. Is it so? Or am I wrong? What can be done to make nginx work in proxy mode without dancing with Apache with a similar configuration?
2. Before putting something to the client, I want to experiment on my home computer. I just have Ubuntu. But the client has CentOS with Apache and a website already installed. Are there any tuning differences or any preliminary dances that need to be considered?
3. The client has two virtual machines running: on port 80 and a mirror on port 443. Do I need to add something to the config?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vit, 2014-01-10
@fornit1917

What can be done to make nginx work in proxy mode without dancing with Apache with a similar configuration?

You can set the proxy in location /
Then everything will be proxied fairly transparently to Apache, and htaccess will work fine. But if you want nginx to give statics and not Apache, then you need to configure a separate location for statics.
There is no fundamental difference. It differs only in the structure of the configs (they are divided into files differently, the files and folders with configs are called differently, etc.), but the essence is the same.
On CentOS, the truth is often SELinux is enabled, which often adds additional crap during configuration.
Actually, no one bothers you to raise a virtual machine with CentOS, so that there is maximum similarity with the client server.
This question didn't quite understand what you mean.

V
Vlad Zhivotnev, 2014-01-10
@inkvizitor68sl

> But judging by the configuration script, there may be problems when apache rewrite is enabled from .htaccess
No, it won't. location ~ /\.ht in this case prohibits http access to .ht* files. Apache itself will, of course, have access to these files.
For the dumb proxy mode, you will need something like this config - hastebin.com/dexoqotopu.nginx (provided that Apache is listening on the localhost on port 81)
Of course, you need to fill it with all sorts of error_page, access_log/error_log and so on.
SSL is enabled like this:

listen 443 ssl;
ssl_certificate /var/www/certs/domain.ru-bundled.crt;
ssl_certificate_key /var/www/certs/domain.ru.key;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;

If Apache has the same configuration for both http and https
In centos, the paths to the configs may differ (for Apache - /etc/httpd, for example), but everything is the same.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question