Debian手动安装LNMPA环境及相关配置

  LNMPA是指(Linux/Nginx/MySQL/PHP/Apache),是广泛使用的网站建站环境。以下将详细介绍手动安装上述环境的方式,如需要一键自动脚本安装,可参考https://lnmp.org/install.html进行安装。

  以下以Debian系统为例,说明LNMPA的安装与配置方式。以下命令建议使用root用户进行操作。

安装Apache

  Debian 上安装Apache相对简单,使用下述命令可安装:

sudo apt install apache2
设置URL重写

  apache默认没有开启URL重写, 使用命令行sudo a2enmod rewrite开启重写模块后,打开 /etc/apache2/apache2.conf ,找到 <Directory /var/www/> 部分,将 AllowOverride None 修改为 AllowOverride All。删除 Indexes,保存并重启apache systemctl restart apache2

修改默认端口

  apache在此处是作为后端处理,需要将其默认的80端口设置为其它端口。打开 /etc/apache2/ports.conf,将 Listen 80 部分的数字改成其它的可用端口号,比如 Listen 88。同时注意也要修改 /etc/apache2/sites-available/000-default.conf 中的端口号为88。保存并重启apachesystemctl restart apache2

修改用户组权限

  如果apache默认设置的用户组与我们所需的用户组不一致,则可为其设置指定的用户组。在 /etc/apache2/envvars 中可以找到aache所归属的用户组,比如默认的用户与用户组均为www-data,如果要修改的话可以修改成www。

安装mysql

  由于Debian默认使用MariaDB 在APT的软件包存储库中并没有mysql,需要自行添加存储库。在https://dev.mysql.com/downloads/repo/apt/中提供了存储库包的下载地址,点击下载,复制对应的下载链接。例如:

wget https://dev.mysql.com/get/mysql-apt-config_0.8.22-1_all.deb

apt install ./mysql-apt-config_0.8.22-1_all.deb

  出现以下界面,确认安装参数为以下内容即可。选择[OK]

在这里插入图片描述
  更新软件包存储库并安装MySQL。

sudo apt update
sudo apt install mysql-server libmysqlclient21 libmysqlclient-dev 
sudo apt install default-libmysqlclient-dev 

  在此过程中会出现输入数据库用户root密码的提示,输入二次并确认。

在这里插入图片描述
在这里插入图片描述
  然后会出现密码安全验证选项选择推荐的强验证方式。

在这里插入图片描述

安装php

  Debian 下将 PHP 安装入 Apache 2 的例子:

apt install php-common libapache2-mod-php php-cli

  APT 将自动安装 Apache 2 的 PHP 模块以及所有依赖的库并激活之。应重启动 Apache 以使更改生效,由于安装了MySQL,还需要启用php的MySQL支持。

sudo apt install php-mysql php-curl

  可在/var/www/html目录下放置一个phpinfo.php来检查php环境是否安装正确。文件中填写以下内容:

<?php
phpinfo();
?>

  访问http://ip/phpinfo.php,可查看页面是否正常打开。

phpMyAdmin安装

  使用phpMyAdmin之前,需要为php开启mysqli 与xml的参数项,具体可先参考以下内容进行设置。

apt install php-xml php-mbstring php-gd;

  编辑/etc/php/7.4/apache2/php.ini,将其中的;extension=mysqli;extension=gd2选项前的逗号去除,保存,重启Apache systemctl restart apache2 以使配置生效。

  从https://www.phpmyadmin.net/下载程序,解压后上传至/var/www/htm/phpMyAdmin目录下,访问http://ip:88/phpMyAdmin/,检查访问是否正常。

安装nginx

   使用以下命令安装nginx。

sudo apt install nginx
修改用户权限

  在 /etc/nginx/nginx.conf中,修改默认的用户组 www-datawww

设置网站配置

  设置反向代理,在 /etc/nginx/下新建文件 proxy.conf

proxy_connect_timeout 300s;
proxy_send_timeout   900;
proxy_read_timeout   900;
proxy_buffer_size    32k;
proxy_buffers     4 32k;
proxy_busy_buffers_size 64k;
proxy_redirect     off;
proxy_hide_header  Vary;
proxy_set_header   Accept-Encoding '';
proxy_set_header   Host   $http_host;
proxy_set_header   Referer $http_referer;
proxy_set_header   Cookie $http_cookie;
proxy_set_header   X-Real-IP  $remote_addr;
proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header   X-Forwarded-Proto $scheme;

  修改默认的配置文件/etc/nginx/sites-available/default,其中添加以下内容:

    # deny running scripts inside writable directories
    location ~* /(images|cache|media|logs|tmp)/.*\.(php|pl|py|jsp|asp|sh|cgi)$ {
            return 403;
            error_page 403 /403_error.html;
    }
	
    location /
    {
        try_files $uri @apache;
    }

    location @apache
    {
        internal;
        proxy_pass http://127.0.0.1:88;
        include proxy.conf;
    }

    location ~ [^/]\.php(/|$)
    {
        proxy_pass http://127.0.0.1:88;
        include proxy.conf;
    }

  重启nginx。 /etc/init.d/nginx restart

安装证书

  安装证书使用 acme.sh进行,acme.sh可帮助用户自动申请证书,并且在证书快到期时自动续期。

  首先进行证书的安装。

curl  https://get.acme.sh | sh -s email=my@example.com

  在安装完成后,断开并重新连接终端。运行以下内容以执行证书申请。其中要将 www.mydomain.com 替换为其它的域名,/home/wwwroot/mydomain.com 替换为服务器的地址。

acme.sh  --issue -d www.mydomain.com  --webroot  /home/wwwroot/mydomain.com/  --server buypass

  安装证书。

acme.sh --install-cert -d example.com \
--key-file       /path/to/keyfile/in/nginx/key.pem  \
--fullchain-file /path/to/fullchain/nginx/cert.pem \
--reloadcmd     "service nginx force-reload"

  申请完成的证书在 /home/{username}/.acme.sh/的目录中,请记住以上内容。

创建SSL配置文件

  在Nginx的配置文件目录/etc/nginx/sites-available/中创建一个名为 ssl.conf 的文件,文件内容填写如下。将其中的 mydomain.com 替换为实际的域名。

server
    {
        listen 443 ssl http2;
        #listen [::]:443 ssl http2;
        server_name isoface.net ;
        index index.html index.htm index.php default.html default.htm default.php;
        root  /home/michael/homepage;
        client_max_body_size 512M;

        ssl_certificate /home/michael/.acme.sh/mydomain.com/mydomain.com.cer;
        ssl_certificate_key /home/michael/.acme.sh/mydomain.com/mydomain.com.key;
        ssl_session_timeout 5m;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
        ssl_prefer_server_ciphers on;
        ssl_ciphers "TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256:EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5";
        ssl_session_cache builtin:1000 shared:SSL:10m;

        #error_page   404   /404.html;

        # Deny access to PHP files in specific directory
        #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }
	
        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }

        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }

        location ~ /.well-known {
            allow all;
        }

        location ~ /\.
        {
            deny all;
        }

        # deny running scripts inside writable directories
        location ~* /(images|cache|media|logs|tmp)/.*\.(php|pl|py|jsp|asp|sh|cgi)$ {
	        return 403;
                error_page 403 /403_error.html;
        }

        location / {
		# First attempt to serve request as file, then
		# as directory, then fall back to displaying a 404.
		try_files $uri @apache;
	}
        
        location @apache{
                internal;
                proxy_pass http://127.0.0.1:88;
                include proxy.conf;
        }
        
        location ~ [^/]\.php(/|$){
                proxy_pass http://127.0.0.1:88;
                include proxy.conf;
        }

        access_log  /home/michael/www.isoface.cn.log;
    }

  同步修改 /etc/nginx/sites-available/default

##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# https://www.nginx.com/resources/wiki/start/
# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
# https://wiki.debian.org/Nginx/DirectoryStructure
#
# In most cases, administrators will remove this file from sites-enabled/ and
# leave it as reference inside of sites-available where it will continue to be
# updated by the nginx packaging team.
#
# This file will automatically load configuration files provided by other
# applications, such as Drupal or Wordpress. These applications will be made
# available underneath a path with that package name, such as /drupal8.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##

# Default server configuration
#
server {
	listen 80;
	listen [::]:80;
   server_name isoface.net; 
   rewrite ^(.*)$ https://${server_name}$1 permanent;
   client_max_body_size 512M;
        
	# SSL configuration
	#
	# listen 443 ssl default_server;
	# listen [::]:443 ssl default_server;
	#
	# Note: You should disable gzip for SSL traffic.
	# See: https://bugs.debian.org/773332
	#
	# Read up on ssl_ciphers to ensure a secure configuration.
	# See: https://bugs.debian.org/765782
	#
	# Self signed certs generated by the ssl-cert package
	# Don't use them in a production server!
	#
	# include snippets/snakeoil.conf;

	root /home/michael/homepage;

	# Add index.php to the list if you are using PHP
	index index.html index.htm index.php;

	#server_name isoface.net;

        # deny running scripts inside writable directories
        location ~* /(images|cache|media|logs|tmp)/.*\.(php|pl|py|jsp|asp|sh|cgi)$ {
	        return 403;
                error_page 403 /403_error.html;
        }

        location / {
		# First attempt to serve request as file, then
		# as directory, then fall back to displaying a 404.
		try_files $uri @apache;
	}
        
        location @apache{
                internal;
                proxy_pass http://127.0.0.1:88;
                include proxy.conf;
        }
        
        location ~ [^/]\.php(/|$){
                proxy_pass http://127.0.0.1:88;
                include proxy.conf;
        }
	# pass PHP scripts to FastCGI server
	#
	#location ~ \.php$ {
	#	include snippets/fastcgi-php.conf;
	#
	#	# With php-fpm (or other unix sockets):
	#	fastcgi_pass unix:/run/php/php7.4-fpm.sock;
	#	# With php-cgi (or other tcp sockets):
	#	fastcgi_pass 127.0.0.1:9000;
	#}

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


# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
#	listen 80;
#	listen [::]:80;
#
#	server_name example.com;
#
#	root /var/www/example.com;
#	index index.html;
#
#	location / {
#		try_files $uri $uri/ =404;
#	}
#}

  为当前文件创建软连接。

ln -s /etc/nginx/sites-available/ssl.conf /etc/nginx/sites-enabled/ssl.conf

  重启nginx。 /etc/init.d/nginx restart。此时网站已可以使用https进行访问。

主域名访问时跳转至子目录设置

  如果要访问主域名时,要将访问链接定向至子目录中,则按以下方式进行设置。在主目录中创建一个名为 .htaccess文件,按照以下方式写入。

# Turn mod_rewrite on
RewriteEngine on

#Hide the joomla subdirectory isoface
RewriteCond %{REQUEST_URI} !^/isoface/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /isoface/$1 [L] 
RewriteRule ^(/)?$ isoface/index.php [L]

设定文件上传的大小限制

  在nginx 中设置 配置文件,在设定的配置文件defaultssl.confserver部分添加 client_max_body_size 512M;

  修改 /etc/php/7.4/apache2/php.ini

post_max_size = 512M

upload_max_filesize = 512M

设置apache 后端获取真实IP

  通过以下命令启用获取真实IP的模块:

a2enmod remoteip

  编辑 /etc/apache2/apach2.conf 文件,在其中添加

RemoteIPHeader X-Forwarded-For
RemoteIPInternalProxy 127.0.0.1

在配置文件中找到

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined

  将其中的 %h 改成 %a,使用 systemctl restart apache2 重启模块。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Ubuntu Debian(NGINX/PHP/MYSQL)快速配置工具LNMP安装 Ubuntu Debian安装基于debian apt-get 快速配置安装nginx php mysql等。LNMP安装Ubuntu Debian(NGINX/PHP/MYSQL)快速配置工具经测试,整个过程约2-5分钟完成。各种组件均使用最新稳定版。加入php host功能限制每个网站的访问目录,防止跨目录,更安全!解决nginx 0day漏洞! DebianLNMP特点:1. 独特的DebianLNMP安全增强设置。2. 新软件库基于http://www.dotdeb.org/可保持同步更新。3. Nginx MySQL PHP 全部升级到最新稳定版本。4. 快捷的安装脚本,快速安装开源LNMP软件组合。5. 适合懒人+初学者。随着时间变迁,安装的版本会是更新版本。6. 最快安装、最新稳定版、最省资源! Ubuntu Debian(NGINX/PHP/MYSQL)LNMP安装 直接给出安装方法:最快安装、最新稳定版、最省资源! root@DebianLNMP-Jimmyli:~# wget http://sourceforge.net/projects/debian-lnmp/files/DebianLNMP/DebianLNMP-Jimmyli.sh root@DebianLNMP-Jimmyli:~# sh DebianLNMP-Jimmyli.sh 输入域名,回车。 接着输入MYSQL root用户密码,再次输入确认MYSQL root用户密码,等待安装完成。整个过程约2-5分钟。 安装完成了! 一如既往,安装快捷方便、迅速! 直接给出安装方法:最快安装、最新稳定版、最省资源! 两步安装即完成命令(Pro加强版) root@DebianLNMP-Jimmyli:~# wget http://sourceforge.net/projects/debian-lnmp/files/DebianLNMP/DebianLNMP-Pro-Jimmyli.sh root@DebianLNMP-Jimmyli:~# sh DebianLNMP-Pro-Jimmyli.sh DebianLNMP加强版? 延续DebianLNMP全部功能...新增PHP5插件ImageMagick、XCache、memcache、curl、MCrypt。 DebianLNMP一键安装LNMP状态管理: 安装完成后,管理Nginx、PHP5、MySQL已经有标准管理命令,其状态管理沿用了Linux通用性。 Nginx状态管理 /etc/init.d/nginx {start|stop|restart|reload|force-reload|status|configtest}PHP5-FPM状态管理 /etc/init.d/php5-fpm {start|stop|status|restart|reload|force-reload}MySQL状态管理/etc/init.d/mysql {start|stop|restart|reload|force-reload|status} Nginx nginx.conf:/etc/nginx/nginx.conf MySQL my.cnf:/etc/mysql/my.cnf PHP php.ini:/etc/php5/fpm/php.ini DebianLNMP一键安装LNMP效果图: Ubuntu Debian(NGINX/PHP/MYSQL)快速配置工具 Debian6系统下使用之前发布的“DebianLNMP”服务器软件套件,DebianLNMP一键安装包是一个快捷的服务器套件,轻轻松松全自动安装LNMP(Nginx、MySQL、PHP、phpMyAdmin)可直接用再生产环境。现在我们已经在Debian/UbuntuVPS(VDS)或独立主机安装LNMP安装最快最新(Nginx、MySQL、PHP、phpMyAdmin)生产环境。 下面介绍配套的DebianLNMP虚拟主机管理工具,快速创建Nginx PHP5.3 MySQL配置。 什么是DebianLNMP虚拟主机管理工具? 使用DebianLNMP一键安装包,安装好Nginx/PHP5.3/MySQL环境后,需要创建添加、新建、删除虚拟主机。它能管理多域名(子域名)的虚拟主机,在Debian系统中以向导的形式管理,按照向导问题选择相应功能即可快速创建。 Debian虚拟主机管理软件?Debian系统安装LNMP环境只需要两条命令,Debian6一键安装DebianLNMP最快.最新.最省!同样,管理LNMP虚拟主机

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值