Improved Nginx virtual host config example (documentation).

This commit is contained in:
Dmitry Khomutov 2017-09-17 20:22:23 +07:00
parent 06cdf35337
commit 89fc49582c

View file

@ -10,21 +10,35 @@ Nginx Example
``` ```
server { server {
... standard virtual host ... charset utf-8;
client_max_body_size 128M;
location / { listen *:80;
try_files $uri @php-censor;
}
location @php-censor { server_name php-censor.local www.php-censor.local;
# Pass to FastCGI: root /var/www/php-censor.local/public;
fastcgi_pass unix:/path/to/phpfpm.sock;
fastcgi_index index.php; #access_log /var/www/php-censor.local/runtime/nginx_access.log;
fastcgi_buffers 256 4k; error_log /var/www/php-censor.local/runtime/nginx_errors.log warn;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root/index.php; location ~* \.(htm|html|xhtml|jpg|jpeg|gif|png|css|zip|tar|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|wav|bmp|rtf|swf|ico|flv|txt|docx|xlsx)$ {
fastcgi_param SCRIPT_NAME index.php; try_files $uri @fpm;
} expires 30d;
}
location / {
try_files $uri @fpm;
}
location @fpm {
fastcgi_pass unix:/var/run/php/php-fpm.sock;
include fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
fastcgi_param SCRIPT_NAME index.php;
}
} }
``` ```
@ -47,15 +61,17 @@ following to a `.htaccess` file in your PHP Censor `/public` directory.
- Edit virtual host in apache2. - Edit virtual host in apache2.
``` ```
<VirtualHost *:80> <VirtualHost *:80>
ServerAdmin user@domain.com ServerAdmin admin@php-censor.local
DocumentRoot /var/www/php-censor.local/public DocumentRoot /var/www/php-censor.local/public
ServerName php-censor.local ServerName php-censor.local
ServerAlias www.php-censor.local
<Directory /var/www/php-censor.local/public/> <Directory /var/www/php-censor.local/public/ >
Options Indexes FollowSymLinks Options Indexes FollowSymLinks
AllowOverride All AllowOverride All
Require all granted Require all granted
</Directory> </Directory>
ErrorLog ${APACHE_LOG_DIR}/php-censor-error_log ErrorLog ${APACHE_LOG_DIR}/php-censor-error_log
CustomLog ${APACHE_LOG_DIR}/php-censor-access_log combined CustomLog ${APACHE_LOG_DIR}/php-censor-access_log combined
</VirtualHost> </VirtualHost>
@ -63,7 +79,7 @@ following to a `.htaccess` file in your PHP Censor `/public` directory.
- Add in /etc/hosts - Add in /etc/hosts
``` ```
127.0.0.1 php-censor.local 127.0.0.1 php-censor.local www.php-censor.local
``` ```
Built-in PHP Server Example Built-in PHP Server Example