兰空图床搭建 作者: zorth 时间: 2024-11-23 分类: 默认分类 ![](https://zorth-1305096201.cos.ap-guangzhou.myqcloud.com/undefined20241123200945.png) 列出php的dnf源 [root@iZuf61llk9btoze85qtbmzZ ~]# dnf list php CentOS Stream 9 - BaseOS 34 MB/s | 8.3 MB 00:00 CentOS Stream 9 - AppStream 53 MB/s | 21 MB 00:00 CentOS Stream 9 - Extras packages 426 kB/s | 19 kB 00:00 Available Packages php.x86_64 8.0.30-1.el9 appstream [root@iZuf61llk9btoze85qtbmzZ ~]# 非常好,8.0.30,可以直接用了 [root@iZuf61llk9btoze85qtbmzZ ~]# dnf install php [root@iZuf61llk9btoze85qtbmzZ ~]# php -v PHP 8.0.30 (cli) (built: Aug 3 2023 17:13:08) ( NTS gcc x86_64 ) Copyright (c) The PHP Group Zend Engine v4.0.30, Copyright (c) Zend Technologies with Zend OPcache v8.0.30, Copyright (c), by Zend Technologies 下面开始安装nginx,安装好之后记得启动nginx [root@iZuf61llk9btoze85qtbmzZ ~]# dnf install nginx [root@iZuf61llk9btoze85qtbmzZ ~]# nginx -v nginx version: nginx/1.20.1 [root@iZuf61llk9btoze85qtbmzZ ~]# ps aux | grep nginx root 4721 0.0 0.1 6408 2304 pts/0 S+ 13:09 0:00 grep --color=auto nginx [root@iZuf61llk9btoze85qtbmzZ ~]# systemctl start nginx [root@iZuf61llk9btoze85qtbmzZ ~]# ps aux | grep nginx root 4728 0.0 0.0 11236 1632 ? Ss 13:09 0:00 nginx: master process /usr/sbin/nginx nginx 4729 0.0 0.2 15564 5216 ? S 13:09 0:00 nginx: worker process nginx 4730 0.0 0.3 15564 5344 ? S 13:09 0:00 nginx: worker process root 4737 0.0 0.1 6408 2304 pts/0 S+ 13:09 0:00 grep --color=auto nginx 启动nginx之后,可以直接访问网站了: ![image.png](https://note.youdao.com/yws/res/1/WEBRESOURCE6d4677ad43d90956d1293cd90c31c061) 进入nginx路径,开始配置https,操作配置文件之前记得备份 [root@iZuf61llk9btoze85qtbmzZ nginx]# cd /etc/nginx/ [root@iZuf61llk9btoze85qtbmzZ nginx]# cp nginx.conf nginx.conf.bak [root@iZuf61llk9btoze85qtbmzZ nginx]# 在此之前先去配置一下域名的dns,把我的域名和ip绑定好。 ![image.png](https://note.youdao.com/yws/res/0/WEBRESOURCE5587d5d43464a152cc7062301d19a350) 这里有一个很关键的地方,使用cf作为dns服务器的时候,还需要设置一下SSL的强制HTTPS ![image.png](https://note.youdao.com/yws/res/4/WEBRESOURCE38317958c014c0328d0b7cf55d256514) 现在开始配置nginx的配置文件: # HTTP服务器(重定向到HTTPS) server { listen 80; listen [::]:80; server_name zorth.top; # 替换为你的域名 # 将所有HTTP请求重定向到HTTPS return 301 https://$server_name$request_uri; } # HTTPS服务器 server { listen 443 ssl; listen [::]:443 ssl; server_name zorth.top; # 替换为你的域名 # SSL配置 ssl_certificate /path/to/your/certificate.crt; # 替换为你的证书路径 ssl_certificate_key /path/to/your/private.key; # 替换为你的私钥路径 # SSL安全配置 ssl_protocols TLSv1.2 TLSv1.3; ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384; ssl_prefer_server_ciphers off; # 网站根目录 root /usr/share/nginx/html; # 替换为你的网站目录 index index.php index.html index.htm; location / { try_files $uri $uri/ /index.php?$query_string; } # PHP配置 location ~ \.php$ { fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; # 如果使用TCP,改为 127.0.0.1:9000 fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } # 禁止访问 .htaccess 文件 location ~ /\.ht { deny all; } } 修改完配置之后,记得验证一下配置: [root@iZuf61llk9btoze85qtbmzZ nginx]# nginx -t nginx: [emerg] cannot load certificate "/path/to/your/certificate.crt": BIO_new_file() failed (SSL: error:80000002:system library::No such file or directory:calling fopen(/path/to/your/certificate.crt, r) error:10000080:BIO routines::no such file) nginx: configuration file /etc/nginx/nginx.conf test failed [root@iZuf61llk9btoze85qtbmzZ nginx]# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful [root@iZuf61llk9btoze85qtbmzZ nginx]# systemctl restart nginx 再次访问刚才的域名时,会直接重定向到https了 ![image.png](https://note.youdao.com/yws/res/3/WEBRESOURCEfff93410ce04d94d96b5b1d1d3a0a4c3) ![image.png](https://note.youdao.com/yws/res/f/WEBRESOURCE1903c4a491d17ffe03b11bad66289b4f) nginx配置完毕了,开始安装图床 [root@iZuf61llk9btoze85qtbmzZ nginx]# cd /usr/share/nginx/html/ [root@iZuf61llk9btoze85qtbmzZ html]# ll total 22356 -rw-r--r-- 1 root root 3971 Jul 16 07:21 404.html -rw-r--r-- 1 root root 4020 Jul 16 07:21 50x.html drwxr-xr-x 2 root root 27 Nov 23 13:08 icons lrwxrwxrwx 1 root root 25 Jul 16 07:22 index.html -> ../../testpage/index.html -rw-r--r-- 1 root root 22876343 Nov 23 13:32 lsky-pro-2.1.zip -rw-r--r-- 1 root root 368 Jul 16 07:21 nginx-logo.png lrwxrwxrwx 1 root root 14 Jul 16 07:22 poweredby.png -> nginx-logo.png lrwxrwxrwx 1 root root 37 Jul 16 07:22 system_noindex_logo.png -> ../../pixmaps/system-noindex-logo.png [root@iZuf61llk9btoze85qtbmzZ html]# 上传安装包之后,解压安装包。![image.png](https://note.youdao.com/yws/res/6/WEBRESOURCEf98d22b0e002a18e1c58de03ef076436) 我这里在root路径下解压了,然后将配置指向了public路径。 标签: none