Цикл статей «Настройка веб сервера Debian 7 + nginx + apache»: первая и вторая части.
Данная статья актуальна на начало 2015 года для настройки Debian 7 в качестве хостинга для личных сайтов.
В качестве прокси и кэширования статики используется nginx, как основной веб-сервер apache.
Установка php, mysql, apache, nginx. Комментариев будет мало, т.к. здесь все стандартно и в интернете разжевано на многочисленых ресурсах.
Выполняем команды последовательно
apt-get update apt-get install apache2 a2enmod rewrite apt-get install mysql-serverТут небольшой момент по безопасной настройке mysql. Пишем в консоли.
mysql_secure_installationДалее следуйте ответам указанным ниже
By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n] y ... Success! Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] y ... Success! By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n] y - Dropping test database... ... Success! - Removing privileges on test database... ... Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] y ... Success! Cleaning up...Продолжаем установку php и mod_rpaf, чтобы апач распознавал реальные IP посетителей.
apt-get install php5 php-pear php5-mysql apt-get install -y libapache2-mod-rpaf service apache2 restart apt-get install nginxСоздаем пользователя в системе, например, webmaster и наши сайты будут хранится в папках /home/webmaster/*
p.s. создать пользователя можно в любой панели, либо через консоль, не забудьте добавить его в необходимые группы.Условимся, что nginx будет слушать 80 и 443 порты, а перекидывать будет на 81 порт, который и будет слушать apache.
Начинаем настройку nginx. Пусть наш сайт desome.net. Это примерный рабочий файл конфигурации.
p.s. новые домены добавлять по аналогии./etc/nginx/nginx.conf
user www-data; worker_processes 4; error_log /var/log/nginx/error.log crit; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; client_max_body_size 8m; sendfile on; #tcp_nopush on; keepalive_timeout 15; gzip on; gzip_comp_level 6; gzip_min_length 800; gzip_proxied expired no-cache no-store private auth; gzip_types text/plain text/javascript text/css application/javascript application/x-javascript text/xml application/xml; charset UTF8; include /etc/nginx/conf.d/*.conf; # desome.net 80, 443 server { listen 80; listen 443 ssl; server_name www.desome.net desome.net; set $root_path /home/webmaster/desome.net/; index index.php index.html index.htm; location ~* ^.+\.(jpg|jpeg|gif|png|svg|js|css|pdf|pptx?|docx?|xlsx?|rtf|xpi|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar|swf)$ { expires 28d; access_log off; root $root_path; error_page 404 = @fallback; } location / { proxy_pass http://127.0.0.1:81; proxy_redirect http://127.0.0.1:81/ /; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Real-IP $remote_addr; } location @fallback { proxy_pass http://127.0.0.1:81; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Real-IP $remote_addr; } } }Coming soon…