分类 linux 下的文章

  • 执行安装
yum install squid -y
yum install httpd-tools -y
  • 生成密码文件
mkdir /etc/squid3/
#wuloves 是用户名
htpasswd -cd /etc/squid3/passwords wuloves
#提示输入密码,比如输入12345678, 这边限制密码长度必须为8位数

test 12345678
  • 测试密码
/usr/lib64/squid/basic_ncsa_auth /etc/squid3/passwords
#输入用户名 密码
test  12345678
#提示ok说明成功
ok
#ctrl+c退出
  • 配置squid.conf文件
vi /etc/squid/squid.conf
#在最前面添加,如果密码认证放在 http_access allow all 后面,会有可能导致密码不鉴权了
auth_param basic program /usr/lib64/squid/basic_ncsa_auth /etc/squid3/passwords
auth_param basic realm proxy
acl authenticated proxy_auth REQUIRED
http_access allow authenticated

# And finally deny all other access to this proxy
http_access allow all

#这里是端口号,可以按需修改
#http_port 3128 这样写会同时监听ipv6和ipv4的端口,推荐适应下面的配置方法。
http_port 0.0.0.0:3128
  • 启动,停止,重启等
#启动start
systemctl start squid.service
#停止stop
systemctl stop squid.service
#重启stop
systemctl restart squid.service
#配置开机自启动
systemctl enable squid.service
#关闭开机自启动
systemctl disable squid.service
#查看运行状态
systemctl status squid.service
  • 测试代理访问

firewall-cmd --permanent --zone=public --add-port=444/tcp
systemctl restart firewalld.service

测试
curl -x test:12345678@192.168.3.6:3128 https://www.wuloves.com

下面是配置方式2

yum install squid
systemctl restart squid.service
systemctl enable squid.service

编辑配置文件, 在开头处增加即可
vim /etc/squid/squid.conf

acl localnet src 0.0.0.0/0
# http_port 3128 >>> http_port 3129

重启服务即可

默认代理端口 3128

遇到问题
Google不能访问,github正常,在对应的主机上访问Google正常
是因为代理被大陆网关给拦截了

tracteroute路由追踪正常

代理使用增加鉴权

  • htpasswd生成passwd文件并创建用户 squiduser
htpasswd  -c /etc/squid/passwd squiduser

如果命令不能使用, 执行 
yum install httpd
  • /etc/squid/squid.conf 增加内容
auth_param basic program /usr/lib64/squid/basic_ncsa_auth /etc/squid/passwd
acl auth_user proxy_auth REQUIRED
http_access allow auth_user
  • 重启squid #systemctl restart squid

  • 下载链接
http://isoredirect.centos.org/centos/7/isos/x86_64/

http://mirrors.aliyun.com/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-Minimal-2009.iso
973.0 MB    2020-11-03 22:55
  • 安装后需要做的基本动作
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# vi ifcfg-ens32
ifcfg-ens32  ifcfg-lo

修改为 ONBOOT=yes
[root@localhost network-scripts]# service network restart

[root@localhost ~]# yum install net-tools -y
使用命令yum install net-tools -y安装,完成以后,ifconfig就可以用了

  • 相关命令
# 查看当前时间
date
# 修改时间
date -s "2000-01-01 00:00:00"
  • 执行时间同步
a=`curl http://www.wuloves.com/tool/date.php>&1`
date -s "$a"
hwclock -w
date

注意点

1. 每次安装完服务器都记得重启下查询服务器是否开机自启动了
2. 

常用命令

# 重置密码
echo abc123 | passwd --stdin root

Nginx

安装nginx

yum install nginx -y
nginx
# 添加到服务中
systemctl enable nginx.service
# 设置开机自启动
chkconfig nginx on

# 通过服务的方式启动nginx
systemctl start nginx.service

# 查看自定服务开机启动状态
systemctl status nginx

# 结束所有的nginx进程
kill -9 $(ps aux |grep nginx|grep -v grep| awk '{print $2}')


返回数据中, nginx.service; 后面的状态为是否开机自启动的呈现
nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2021-10-11 17:00:38 CST; 11min ago

配置反向代理

一般用于给网站做代理, https需要有网站的证书, 需要网站域名解析过去,且需要配置该域名的实际目标的host才行,以及配置对应的域名证书
↓↓↓↓↓ ssl代理配置 ↓↓↓↓↓

server {
    listen 443 ssl;   #SSL协议访问端口号为443。此处如未添加ssl,可能会造成Nginx无法启动。
    server_name api.wuloves.test;  #将localhost修改为您证书绑定的域名,例如:www.example.com。
    ssl_certificate key/api.wuloves.test.pem;   #将domain name.pem替换成您证书的文件名。
    ssl_certificate_key key/api.wuloves.test.key;   #将domain name.key替换成您证书的密钥文件名。
    # ssl_client_certificate key/ca.crt;
    ssl_session_timeout 30m;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;  #使用此加密套件。
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;   #使用该协议进行配置。
    ssl_prefer_server_ciphers on; 
    ssl_verify_client      off;

    location / {
        proxy_pass https://api.wuloves.test/;
        # proxy_ssl_certificate key/api.wuloves.test.pem;
        # proxy_ssl_certificate_key key/api.wuloves.test.key;

        # proxy_ssl_protocols           TLSv1 TLSv1.1 TLSv1.2;
        # proxy_ssl_ciphers             HIGH:!aNULL:!MD5;
        # proxy_ssl_trusted_certificate key/ca.crt;

        # proxy_ssl_verify        off;
        # proxy_ssl_verify_depth  2;
        # proxy_ssl_session_reuse on;
    }
    access_log logs/$server_name.success.ssl.log;
    error_log logs/api.wuloves.test.error.ssl.log; # 错误日志路径中不允许使用变量
}

配置正向代理(测试未通过)

↓↓↓↓↓ 正向代理配置 ↓↓↓↓↓

server {
    listen 18081;
    server_name _;
    location / {
    resolver 8.8.8.8;
    proxy_pass $scheme://$host$request_uri;
    }
}

Nginx变量列表

$args #这个变量等于请求行中的参数。
$content_length #请求头中的Content-length字段。
$content_type #请求头中的Content-Type字段。
$document_root #当前请求在root指令中指定的值。
$host #请求主机头字段,否则为服务器名称。
$http_user_agent #客户端agent信息
$http_cookie #客户端cookie信息
$limit_rate #这个变量可以限制连接速率。
$request_body_file #客户端请求主体信息的临时文件名。
$request_method #客户端请求的动作,通常为GET或POST。
$remote_addr #客户端的IP地址。
$remote_port #客户端的端口。
$remote_user #已经经过Auth Basic Module验证的用户名。
$request_filename #当前请求的文件路径,由root或alias指令与URI请求生成。
$query_string #与$args相同。
$scheme #HTTP方法(如http,https)。
$server_protocol #请求使用的协议,通常是HTTP/1.0或HTTP/1.1。
$server_addr #服务器地址,在完成一次系统调用后可以确定这个值。
$server_name #服务器名称。
$server_port #请求到达服务器的端口号。
$request_uri #包含请求参数的原始URI,不包含主机名,如:”/foo/bar.php?arg=baz”。
$uri #不带请求参数的当前URI,$uri不包含主机名,如”/foo/bar.html”。
$document_uri #与$uri相同。

PS

windows本地启动php-cgi
php-cgi.exe -b 127.0.0.1:9000 -c D:/server/web/server/php/php.ini