|
| 1 | +.. index:: |
| 2 | + single: Web Server |
| 3 | + |
| 4 | +Configuring a web server |
| 5 | +======================== |
| 6 | + |
| 7 | +The web directory is the home of all of your application's public and static |
| 8 | +files. Including images, stylesheets and JavaScript files. It is also where the |
| 9 | +front controllers live. For more details, see the chapter about |
| 10 | +:ref:`the-web-directory`. |
| 11 | + |
| 12 | +The web directory is the one that you will need to configure in your webserver |
| 13 | +as the documentroot. In the examples below, this directory is in |
| 14 | +``/var/www/project/web/``. |
| 15 | + |
| 16 | +Apache2 |
| 17 | +------- |
| 18 | + |
| 19 | +For advanced Apache configuration options, see the official `Apache`_ |
| 20 | +documentation. The minimum basics to get your application running under Apache2 |
| 21 | +are: |
| 22 | + |
| 23 | +.. code-block:: Apache2 |
| 24 | +
|
| 25 | + <VirtualHost *:80> |
| 26 | + ServerName www.domain.tld |
| 27 | +
|
| 28 | + DocumentRoot /var/www/project/web |
| 29 | + <Directory /var/www/project/web> |
| 30 | + # enable the .htaccess rewrites |
| 31 | + AllowOverride All |
| 32 | + Order allow,deny |
| 33 | + Allow from All |
| 34 | + </Directory> |
| 35 | + |
| 36 | + ErrorLog /var/log/apache2/project_error.log |
| 37 | + CustomLog /var/log/apache2/project_access.log combined |
| 38 | + </VirtualHost> |
| 39 | +
|
| 40 | +.. note:: |
| 41 | + |
| 42 | + For performance reasons, you will probably want to set |
| 43 | + ``AllowOverride None`` and implement your ``.htaccess`` into the |
| 44 | + vhost config. |
| 45 | + |
| 46 | +Nginx |
| 47 | +----- |
| 48 | + |
| 49 | +For advanced Nginx configuration options, see the official `Nginx`_ |
| 50 | +documentation. The minimum basics to get your application running under Nginx |
| 51 | +are: |
| 52 | + |
| 53 | +.. code-block:: nginx |
| 54 | +
|
| 55 | + server { |
| 56 | + server_name www.domain.tld; |
| 57 | + root /var/www/project/web; |
| 58 | +
|
| 59 | + location / { |
| 60 | + # try to serve file directly, fallback to rewrite |
| 61 | + try_files $uri @rewriteapp; |
| 62 | + } |
| 63 | +
|
| 64 | + location @rewriteapp { |
| 65 | + # rewrite all to app.php |
| 66 | + rewrite ^(.*)$ /app.php/$1 last; |
| 67 | + } |
| 68 | +
|
| 69 | + location ~ ^/(config|app|app_dev)\.php(/|$) { |
| 70 | + fastcgi_pass unix:/var/run/php5-fpm.sock; |
| 71 | + fastcgi_split_path_info ^(.+\.php)(/.*)$; |
| 72 | + include fastcgi_params; |
| 73 | + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; |
| 74 | + fastcgi_param HTTPS off; |
| 75 | + } |
| 76 | + |
| 77 | + error_log /var/log/nginx/project_error.log; |
| 78 | + access_log /var/log/nginx/project_access.log; |
| 79 | + } |
| 80 | +
|
| 81 | +.. note:: |
| 82 | + |
| 83 | + Depending on your PHP-FPM config, the ``fastcgi_pass`` can also be |
| 84 | + ``fastcgi_pass 127.0.0.1:9000``. |
| 85 | + |
| 86 | +.. _`Apache`: http://httpd.apache.org/docs/current/mod/core.html#documentroot |
| 87 | +.. _`Nginx`: http://wiki.nginx.org/Symfony |
| 88 | + |
0 commit comments