安装Piwigo画廊在Nginx与Debian Wheezy

安装Piwigo画廊在Nginx与Debian Wheezy

本教程将介绍如何在Debian Wheezy系统上安装和运行带有nginx的piwigo图库站点,配置为vhosts。 Piwigo是一个拥有许多插件的画廊网站。 在这个例子中,我们配置了vhost“gallery.domain.tld”。

安装

安装nginx的软件包

apt-get install nginx php5-fpm php5 php5-mysql php5-pgsql php5-imap php-pear php5-sqlite php5-ldap php5-gd php5-imagick php5-curl php-apc
apt-get install php5-mcrypt php5-pspell php5-xmlrpc php5-xsl php5-cgi php-auth php-auth-sasl php-net-smtp

安装MySQL服务器

apt-get install mysql-server

配置Nginx

删除默认站点(可选)

rm -f /etc/nginx/sites-enabled/default

为vhost创建模板文件

cd /etc/nginx/sites-available/
touch template-with-ssl
touch template

Vhost与ssl支持

插入以下文件

nano /etc/nginx/sites-available/template-with-ssl
server {
listen        80;
# .domain.com will match both domain.com and anything.domain.com
server_name www.domain.tld domain.tld;
rewrite ^ https://$server_name$request_uri? permanent;

# It is best to place the root of the server block at the server level, and not the location level
# any location block path will be relative to this root.
root /var/www/www.domain.tld;

# It's always good to set logs, note however you cannot turn off the error log
# setting error_log off; will simply create a file called 'off'.
access_log /var/log/nginx/example.access.log;
error_log /var/log/nginx/example.error.log;

# This can also go in the http { } level
index index.html index.htm index.php;

location / {
# if you're just using wordpress and don't want extra rewrites
# then replace the word @rewrites with /index.php
try_files $uri $uri/ @rewrites;
}

location @rewrites {
# Can put some of your own rewrite rules in here
# for example rewrite ^/~(.*)/(.*)/? /users/$1/$2 last;
# If nothing matches we'll just send it to /index.php
rewrite ^ /index.php last;
}

# This block will catch static file requests, such as images, css, js
# The ?: prefix is a 'non-capturing' mark, meaning we do not require
# the pattern to be captured into $1 which should help improve performance
location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
# Some basic cache-control for static files to be sent to the browser
expires max;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}

# remove the robots line if you want to use wordpress' virtual robots.txt
location = /robots.txt { access_log off; log_not_found off; }
location = /favicon.ico { access_log off; log_not_found off; }

# this prevents hidden files (beginning with a period) from being served
location ~ /\. { access_log off; log_not_found off; deny all; }

location ~ \.php {
fastcgi_param        SCRIPT_NAME $fastcgi_script_name;
fastcgi_param        SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index        index.php;
fastcgi_pass        unix:/var/run/php5-fpm.sock;
include fastcgi_params;
}
}
# just, if you want to use ssl-vhost
server {
listen        443 default ssl;
# .domain.com will match both domain.com and anything.domain.com
server_name www.domain.tld domain.tld;

ssl_certificate        /etc/nginx/ssl/www.domain.tld.crt;
ssl_certificate_key        /etc/nginx/ssl/www.domain.tld.key;
# It is best to place the root of the server block at the server level, and not the location level
# any location block path will be relative to this root.
root /var/www/www.domain.tld;

# It's always good to set logs, note however you cannot turn off the error log
# setting error_log off; will simply create a file called 'off'.
access_log /var/log/nginx/example.access.log;
error_log /var/log/nginx/example.error.log;

# This can also go in the http { } level
index index.html index.htm index.php;

location / {
# if you're just using wordpress and don't want extra rewrites
# then replace the word @rewrites with /index.php
try_files $uri $uri/ @rewrites;
}

location @rewrites {
# Can put some of your own rewrite rules in here
# for example rewrite ^/~(.*)/(.*)/? /users/$1/$2 last;
# If nothing matches we'll just send it to /index.php
rewrite ^ /index.php last;
}

# This block will catch static file requests, such as images, css, js
# The ?: prefix is a 'non-capturing' mark, meaning we do not require
# the pattern to be captured into $1 which should help improve performance
location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
# Some basic cache-control for static files to be sent to the browser
expires max;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}

# remove the robots line if you want to use wordpress' virtual robots.txt
location = /robots.txt { access_log off; log_not_found off; }
location = /favicon.ico { access_log off; log_not_found off; }

# this prevents hidden files (beginning with a period) from being served
location ~ /\. { access_log off; log_not_found off; deny all; }

location ~ \.php {
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index index.php;
fastcgi_pass unix:/var/run/php5-fpm.sock;
include fastcgi_params;

}
}

仅适用于HTTP的Vhost

nano /etc/nginx/sites-available/template
server {
listen        80;
# .domain.com will match both domain.com and anything.domain.com
server_name www.domain.tld domain.tld;
#rewrite ^ https://$server_name$request_uri? permanent;

# It is best to place the root of the server block at the server level, and not the location level
# any location block path will be relative to this root.
root /var/www/www.domain.tld;

# It's always good to set logs, note however you cannot turn off the error log
# setting error_log off; will simply create a file called 'off'.
access_log /var/log/nginx/rugia.access.log;
error_log /var/log/nginx/rugia.error.log;

# This can also go in the http { } level
index index.html index.htm index.php;

location / {
# if you're just using wordpress and don't want extra rewrites
# then replace the word @rewrites with /index.php
try_files $uri $uri/ @rewrites;
}
location @rewrites {
# Can put some of your own rewrite rules in here
# for example rewrite ^/~(.*)/(.*)/? /users/$1/$2 last;
# If nothing matches we'll just send it to /index.php
rewrite ^ /index.php last;
}

# This block will catch static file requests, such as images, css, js
# The ?: prefix is a 'non-capturing' mark, meaning we do not require
# the pattern to be captured into $1 which should help improve performance
location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
# Some basic cache-control for static files to be sent to the browser
expires max;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}

# remove the robots line if you want to use wordpress' virtual robots.txt
location = /robots.txt { access_log off; log_not_found off; }
location = /favicon.ico { access_log off; log_not_found off; }

# this prevents hidden files (beginning with a period) from being served
location ~ /\. { access_log off; log_not_found off; deny all; }

location ~ \.php {
fastcgi_param        SCRIPT_NAME $fastcgi_script_name;
fastcgi_param        SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index        index.php;
fastcgi_pass        unix:/var/run/php5-fpm.sock;
include fastcgi_params;
}
}

创建第一个虚拟主机

使用模板

cp /etc/nginx/sites-available/template /etc/nginx/sites-available/gallery.domain.tld

编辑路径变量

nano /etc/nginx/sites-available/gallery.domain.tld
server_name gallery.domain.tld;
root /var/www/gallery.domain.tld;
access_log /var/log/nginx/gallery.access.log;
error_log /var/log/nginx/gallery.error.log;

创建你的目录结构

mkdir -p /var/www/gallery.domain.tld
chown -R www-data:www-data /var/www

启用您的虚拟主机

ln -s /etc/nginx/sites-available/gallery.domain.tld /etc/nginx/sites-enabled/gallery.domain.tld
现在重新启动服务:
/etc/init.d/php5-fpm restart
/etc/init.d/nginx restart

测试PHP

使用phpinfo创建测试文件:
nano /var/www/gallery.domain.tld/test.php
<?php
 phpinfo();
?>
为了快速测试,只需使用vhost名称编辑 hosts文件;在该示例中,服务器的IP为 192.168.1.10
  192.168.1.10	gallery.domain.tld
现在打开浏览器并导航到:
http://gallery.domain.tld
如果您看到有关安装的php版本的信息页面,一切都可以,现在您可以删除测试文件:
rm -f nano /var/www/gallery.domain.tld/test.php

配置Piwigo

创建数据库和用户

用户名: gallery01
密码: 密码

连接到MySQL:
mysql -u root -p
create database gallery01; grant all on gallery01.* to 'gallery'@'localhost' identified by 'PASSWORD'; flush privileges; \q;

下载适用于piwigo的netinstall-file

cd /var/www/gallery.domain.tld
wget http://piwigo.org/download/dlcounter.php?code=netinstall
mv dlcounter.php\?code\=netinstall netinstall.php
chown www-data:www-data netinstall.php

配置调整

nano /etc/php5/fpm/php.ini
upload_tmp_dir = /tmp 	
upload_max_filesize = 20M 	
max_file_uploads = 20
nano /etc/nginx/nginx.conf
client_max_body_size 20M;         
client_body_buffer_size 128k;

不要忘记重新启动服务:

/etc/init.d/php5-fpm restart
/etc/init.d/nginx restart

使用webinstaller

打开浏览器并导航到:
http://gallery.domain.tld/netinstall.php
赞(52) 打赏
未经允许不得转载:优客志 » 系统运维
分享到:

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏