пятница, 16 января 2015 г.

Symfony2 Nginx and Apache2

Nginx Conf

server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;

        root /PATH_TOSYMFONY_PROJECT/web;

        # Make site accessible from http://localhost/
        server_name localhost;

        location / {
            try_files $uri /app.php$uri$is_args$query_string;
        }

        #
        # Pass (app|app_dev|config).php to apache2
        #
        location ~ ^/(app|app_dev|config)\.php(/|$) {
                #DMZ Only
                #Default Port
                set $_port 80;
                if ($host = EXTERNAL_IP) {
                    set $_port 10880;
                }

                if ($host = INTERNAL_IP) {
                    set $_port 80;
                }
                #End For DMZ
                proxy_pass          http://127.0.0.1:81;
                proxy_set_header    X-Real-IP  $remote_addr;

                proxy_set_header    X-Forwarded-For $remote_addr;
                proxy_set_header    X-Forwarded-Proto $scheme;

                #
                # Нужно для того чтобы симфони могло генерировать урлы без "app.php"
                #
                proxy_set_header    X-Rewrite-URL $request_uri;
                proxy_set_header    X-Original-URL $request_uri;
                proxy_set_header    X-Original-Addr $remote_addr;

                proxy_set_header    Host $host:$_port;

        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        location ~ /\.ht {
                deny all;
        }
}


Apache2 conf

<VirtualHost *:81>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot "/PATH_TOSYMFONY_PROJECT/web"
    DirectoryIndex app.php

    <IfModule env_module>
        SetEnv APPLICATION_ENV development
    </IfModule>

    <Directory "/PATH_TOSYMFONY_PROJECT/web">
        AllowOverride None
        Allow from All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>