Apache配置指南及常见问题排查

Apache 是最流行的 Web 服务器之一,广泛用于托管各种网站和应用。它支持虚拟主机(VirtualHost)功能,可以让你在一台服务器上托管多个域名或站点。本文将分为两部分:

  1. 如何配置 Apache 虚拟主机。
  2. 如何排查和修复常见的配置错误。
Read more

Send Email by Python

Key_points:

  • SMTP服务器地址和端口
    • 使用TLS加密: 587
      1
      2
      server = smtplib.SMTP(smtp_server, smtp_port)
      server.starttls()
    • 使用SSL加密: 465
      1
      server = smtplib.SMTP_SSL(smtp_server, smtp_port)

代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart

# 发送邮件
def send_email():
print("Preparing to send email...")
sender_email = 'your_email@example.com'
receiver_email = 'receiver_email@example.com'
password = 'your_email_password'

smtp_server = 'smtp.yourmail.com'
smtp_port = 587 # SMTP端口, 通常为587(TSL)或465(SSL)

subject = 'subject'
body = 'body'

message = MIMEMultipart()
message['From'] = sender_email
message['To'] = receiver_email
message['Subject'] = subject
message.attach(MIMEText(body, 'plain'))

try:
print("Connecting to SMTP server...")
# If you want to use SSL, use `smtplib.SMTP_SSL()` instead and remove `server.starttls()`
with smtplib.SMTP(smtp_server, smtp_port) as server:
server.starttls() # 使用TLS加密
print("Logging in to SMTP server...")
server.login(sender_email, password) # 登录
print("Sending email...")
server.sendmail(sender_email, receiver_email, message.as_string()) # 发送邮件
print("Email sent successfully.")
except Exception as e:
print(f"Email sent failed: {e}")

# 主函数
def main():
send_mail()

Configure Latex on MacOS

安装MacTex

安装VSCode插件

配置VSCode

设置默认编译器

在VSCode中,打开设置,搜索”latex-workshop.latex.recipes”,将 “args” 部分的内容修改为如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
"name": "latexmk",
"command": "latexmk",
// "args": [
// "-synctex=1",
// "-interaction=nonstopmode",
// "-file-line-error",
// "-pdf",
// "-outdir=%OUTDIR%",
// "%DOC%"
// ],
"args": [
"-xelatex",
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"%DOC%"
],
"env": {}

保存编译

在VSCode中,打开设置,搜索”latex-workshop.latex.autoBuild.run”,将其设置为”onSave”,这样每次保存tex文件时就会自动编译。

使用上次使用的编译器

在VSCode中,打开设置,搜索”latex-workshop.latex.recipe.default”,将其设置为”lastUsed”,这样第一次编译tex文件手动选择选择编译器,后面就会默认使用该选择了。

目前遇到的问题

  • MacOS上编译得到的pdf文件中文字体偏细, 与Windows上的不一样

参考

Understand folder and path configuration in Jekyll

在使用 Jekyll 构建静态网站时,了解如何配置文件夹和路径对于网站的组织和内容管理至关重要。Jekyll 是一个功能强大的静态网站生成器,具有独特的文件夹结构和处理规则。本文将介绍 Jekyll 如何处理不同的文件夹,以及如何通过配置使网站更灵活。

Read more

Use ssh to connect to AWS EC2 instance

1: Create a new key pair

  1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.
  2. In the navigation pane, choose Key Pairs.
  3. Choose Create key pair.
  4. For Key pair name, enter a name for the new key pair, and then choose Create key pair.
  5. Your browser will download the private key file automatically. The private key file is automatically downloaded by your browser. The base file name is the name you specified as the name of your key pair, and the file name extension is .pem. Save the private key file in a safe place.
  6. Choose Close.
  7. Important: You can create a key pair only once. Be sure to save the private key file to your computer. You’ll need to provide the name of your key pair when you launch an instance and the corresponding private key each time you connect to the instance.

2: Connect to your instance

  1. Open a terminal window.
  2. Use the cd command to navigate to the directory where your private key file is located.
  3. Use the following command to set the permissions of your private key file so that only you can read it:
1
chmod 400 /path/my-key-pair.pem
  1. Use the following command to connect to your instance. Replace ec2-user with the appropriate user name for your AMI.
  • For Amazon Linux 2 or the Amazon Linux AMI, the user name is ec2-user.
  • For a CentOS AMI, the user name is centos.
  • For a Debian AMI, the user name is admin.
  • For a Fedora AMI, the user name is ec2-user or fedora.
  • For a RHEL AMI, the user name is ec2-user or root.
  • For a SUSE AMI, the user name is ec2-user or root.
  • For an Ubuntu AMI, the user name is ubuntu. Here my OS is Ubuntu.
  • Otherwise, if ec2-user and root don’t work, check with your AMI provider.
1
ssh -i /path/my-key-pair.pem user_name@ip_address

3: (Optional) Connect to your instance using a password

  1. Open a terminal window.
  2. Use the following command to connect to your instance.
1
ssh user_name@my-instance-ip

I meet Permission denied (publickey) error.

To fix it.

Step1: Firstly I need to use the previous command to connect to my instance.
1
ssh -i /path/my-key-pair.pem user_name@ip_address
Step2: Set up a password for the user using passwd command along with the username.
1
sudo passwd ubuntu
Step 3: Edit sshd_config file.
1
sudo vim /etc/ssh/sshd_config

Find the Line containing PasswordAuthentication parameter and change its value from no to yes.

1
PasswordAuthentication yes

If you want to set up root login, find PermitRootLogin parameter and change its value from prohibit-password to yes

1
PermitRootLogin yes

After this changes save file and exit.

Step 4: Restart the SSH service.
1
2
3
service ssh restart ## for ubuntu

service sshd restart ## for centos
Step 5: Add the .pem file to Local ssh.
1
2
chmod 400 /path/my-key-pair.pem
ssh-add -k /path/my-key-pair.pem
Step 6: Now you can connect to your instance using a password.
1
ssh user_name@my-instance-ip

Useful Commands

Git

When you are using Git, you may encounter some problems. Here are some useful commands to help you solve them.

  1. Set the postBuffer size to 500MB
    When meeting:
1
2
3
4
5
6
error: RPC failed; HTTP 400 curl 22 The requested URL returned error: 400
send-pack: unexpected disconnect while reading sideband packet
Writing objects: 100% (635/635), 2.07 MiB | 2.53 MiB/s, done.
Total 635 (delta 81), reused 0 (delta 0), pack-reused 0
fatal: the remote end hung up unexpectedly
Everything up-to-date

You can set the postBuffer size to 500MB:

1
git config http.postBuffer 524288000