Ubuntu Apache 添加端口

编辑 /etc/apache2/ports.conf,添加你要监听的端口

Listen 8888

设置虚拟主机

<VirtualHost *:8888>
...
</VirtualHost>

Apache 域名跳转到目录

RewriteEngine On
RewriteCond %{SERVER_NAME} =photo.zuoridangnian.com
RewriteRule ^ https://zuoridangnian.com/photo-gallery%{REQUEST_URI} [END,NE,R=permanent]

Ubuntu 20.04 apache开启http2

apt update && apt upgrade
apt install apache2 php7.4-fpm 
a2enmod proxy_fcgi setenvif
a2enconf php7.4-fpm 
a2dismod php7.4 
systemctl restart apache2
a2dismod mpm_prefork 
a2enmod mpm_event 
systemctl restart apache2
systemctl restart php7.4-fpm
a2enmod http2
systemctl restart apache2

Arch Linux服务器配置php-fpm并开启http/2

我之前是用libphp的方式安装的php,就是安装 php7-apache 这个包,但是这种方法不支持http/2,所以我换成了 php-fpm

具体的配置方法看arch wiki就可以了

Apache HTTP Server – ArchWiki (archlinux.org)

但我按wiki的方法配置好后,打开什么页面都是503

原因是我使用的是php7,安装的包也是 php7-fpm,arch linux最新的版本是php8了,所以配置默认是php8的,需要修改一下 SetHandler 

DirectoryIndex index.php index.html
<FilesMatch \.php$>
    SetHandler "proxy:unix:/run/php-fpm7/php-fpm.sock|fcgi://localhost/"
</FilesMatch>

然后重启一下 httpd 服务就行了

开启http/2也很简单 Apache HTTP Server – ArchWiki (archlinux.org)

取消注释

LoadModule http2_module modules/mod_http2.so

加入以下行就行了

Protocols h2 http/1.1

可以在以下网址测试网站是否开启http/2

apache pagespeed配置

apache:

<IfModule pagespeed_module>
    ModPagespeed on
    ModPagespeedEnableFilters inline_css
    ModPagespeedEnableFilters lazyload_images
    AddOutputFilterByType MOD_PAGESPEED_OUTPUT_FILTER text/html
    ModPagespeedEnableFilters convert_gif_to_png
    ModPagespeedEnableFilters convert_jpeg_to_progressive
    ModPagespeedEnableFilters convert_jpeg_to_webp
    ModPagespeedEnableFilters convert_png_to_jpeg
    ModPagespeedEnableFilters convert_to_webp_lossless
    ModPagespeedEnableFilters inline_images
    ModPagespeedEnableFilters recompress_images
    ModPagespeedEnableFilters recompress_jpeg
    ModPagespeedEnableFilters recompress_png
    ModPagespeedEnableFilters recompress_webp
    ModPagespeedEnableFilters jpeg_subsampling
    ModPagespeedEnableFilters remove_comments 
    ModPagespeedEnableFilters Combine_css
    ModPagespeedEnableFilters rewrite_javascript,rewrite_css
    ModPagespeedEnableFilters collapse_whitespace,elide_attributes
    ModPagespeedFileCacheInodeLimit 500000
    ModPagespeedFileCachePath "/var/cache/mod_pagespeed/"
</IfModule>

Ubuntu 20.04 Server装完系统需要做的一些事

打开ufw

ufw allow OpenSSH ## 打开SSH端口

ufw enable ## 启动 ufw

ufw status ## 查看 ufw 状态

ufw allow 8888/tcp ## 放行8888端口

安装pip

apt install python3-pip
pip3 config set global.index-url https://mirrors.ustc.edu.cn/pypi/web/simple

安装lamp

apt install apache2
apt install mysql-server ##mariadb-server

安装PHP

apt install php libapache2-mod-php php-mysql php-curl php-gd php-mbstring php-xml php-xmlrpc php-soap php-intl php-zip
systemctl restart apache2

设置mysql

mysql_secure_installation

mysql

创建数据库
CREATE DATABASE zrdn DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;

创建用户
CREATE USER 'zrdn'@'%' IDENTIFIED WITH mysql_native_password BY 'password';

给权限
GRANT ALL ON zrdn.* TO 'zrdn'@'%';

安装certbot自动配置HTTPS证书

snap install core; sudo snap refresh core
snap install --classic certbot
ln -s /snap/bin/certbot /usr/bin/certbot
certbot --apache

ufw 放行 apache 端口

ufw allow in "Apache Full" ## 80/443

添加用户

adduser sammy

usermod -aG sudo sammy ## 给 sudo 权限

配置用户执行sudo命令不用输入密码

1.配置单用户不用输入密码

linuxconfig ALL=(ALL) NOPASSWD:ALL

2.配置所有sudo组的用户不用输入密码

%sudo   ALL=(ALL:ALL) NOPASSWD:ALL

xampp 开启gzip压缩

首先编辑php.ini,修改zlib.output_compression 为On

然后编辑httpd.conf,取消注释以下两个模块

LoadModule deflate_module modules/mod_deflate.so
LoadModule filter_module modules/mod_filter.so

接下来在httpd.conf文件最下面加入:

SetOutputFilter DEFLATE 

# Set the path to the directory where you wish to apply the gzip compression
# Usually you would like to apply that to the entire htdocs folder, but you can change it
<Directory "C:/xampp/htdocs">  
    <IfModule mod_deflate.c>
        # Add any file type you want
        AddOutputFilterByType DEFLATE text/html
    </IfModule>
</Directory> 

C:/xampp/htdocs为你要开启gzip压缩的web目录,改为你自己的目录即可

开启之后,我的网站首页打开速度对比

加载内容和时间减少一半

windows服务器配置apache php mariadb

主要参考这篇文章 https://superuser.com/questions/748117/how-to-manually-install-apache-php-and-mysql-on-windows 很详细

首先安装apache,windows apache有两个选择: ApacheHaus 或者 Apache Lounge

我这里选择ApacheHaus

下载最先版本,解压压缩包可以看到一个readme文件,安装里面的操作步骤可以安装apache

接下来配置php,php要下载安全线程版本,php怎么配置就不说了,主要是编辑一下httpd.conf文件,导入php模块

LoadModule php7_module "c:\php\php7apache2_4.dll"

<IfModule php7_module>

    AddHandler application/x-httpd-php .php
    AddType application/x-httpd-php .php .html
    PHPIniDir "c:\php"
</IfModule>

需要注意的地方:

配置虚拟主机

取消注释httpd.conf文件的 Include conf/extra/httpd-vhosts.conf 一行,然后在这个文件里配置虚拟主机

我的配置文件:

<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot "C:\Users\Administrator\Desktop\zrdn"
    ServerName zuoridangnian.com
    DirectoryIndex index.php
</VirtualHost>


<VirtualHost *:443>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot "C:\Users\Administrator\Desktop\zrdn"
    ServerName zuoridangnian.com
    DirectoryIndex index.php
	  SSLEngine on
    SSLCertificateFile "C:\Apache24\conf\ssl\4261553_zuoridangnian.com_public.crt"
    SSLCertificateKeyFile "C:\Apache24\conf\ssl\4261553_zuoridangnian.com.key"
</VirtualHost>

默认rewrite模块的没开的

取消注释 LoadModule rewrite_module modules/mod_rewrite.so 一行

然后还需要将AllowOverride改为All

ubuntu 20.04更换网站服务器apache为nginx

首先停用apache

systemctl stop apache2

安装nginx和php-fpm

apt install nginx php-fpm

创建nginx配置文件 nano /etc/nginx/sites-available/zrdn.conf

server {
    listen 80;
    server_name zuoridangnian.com;
    root /var/www/zrdn;

    index index.html index.htm index.php;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
     }

    location ~ /\.ht {
        deny all;
    }

}

启用站点

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

重启nginx

systemctl restart nginx

配置ssl证书,安装certbot nginx

apt-get install certbot python3-certbot-nginx

配置证书

certbot –nginx

选择域名,然后选择第二项,renew 更新证书,然后因为我用了cloudflare的cdn,所以选择No Redirect

如果你也用了cloudflare 并且ssl是flexible模式,则你vps其实可以不用安装ssl证书

重载一下nginx,大功告成

systemctl restart nginx

修改.htaccess文件设置php上传最大值

php_value upload_max_filesize 100M
php_value post_max_size 100M

没有更多文章了