1. 安装Nginx 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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 sudo dnf update sudo dnf install nginx nginx -v sudo nginx -t sudo systemctl start nginx sudo systemctl enable nginx server { listen 80; server_name app.example.com; location / { proxy_pass http://localhost:4000; proxy_set_header Host $host ; 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 ; } } server { listen 443 ssl; server_name app.example.com; ssl_certificate /etc/nginx/certs/app.example.com.pem; ssl_certificate_key /etc/nginx/certs/app.example.com.key; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5; ssl_prefer_server_ciphers on; ssl_session_timeout 10m; ssl_session_cache builtin :1000 shared:SSL:10m; ssl_buffer_size 1400; add_header Strict-Transport-Security max-age=15768000; ssl_stapling on; ssl_stapling_verify on; location / { proxy_pass http://localhost:8088; proxy_set_header Host $host ; 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 ; } } server { listen 443 ssl; server_name paint.roaring.win; ssl_certificate /etc/nginx/certs/app.example.com.pem; ssl_certificate_key /etc/nginx/certs/app.example.com.key; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5; ssl_prefer_server_ciphers on; ssl_session_timeout 10m; ssl_session_cache builtin :1000 shared:SSL:10m; ssl_buffer_size 1400; add_header Strict-Transport-Security max-age=15768000; ssl_stapling on; ssl_stapling_verify on; location / { proxy_pass http://localhost:8003; proxy_set_header Host $host ; 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 ; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade ; proxy_set_header Connection "upgrade" ; } } server { listen 80; server_name paint.roaring.win; return 301 https://$server_name$request_uri ; }
可以修改nginx默认监听端口(将80端口改为其他)
1 2 3 4 5 6 7 8 9 server { listen 80; listen [::]:80; server_name _; root /usr/share/nginx/html; …… }
nginx常用命令:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 sudo systemctl start nginx sudo systemctl stop nginx sudo systemctl restart nginx sudo systemctl status nginx sudo netstat -tlnp | grep nginx sudo systemctl enable nginx sudo systemctl disable nginx
安装SSL证书
acme.sh 自建证书
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 acme.sh --issue -d webgpt.ancientrees.com --nginx acme.sh --install-cert -d webgpt.ancientrees.com \ --key-file /etc/nginx/certs/webgpt.ancientrees.com/key.pem \ --fullchain-file /etc/nginx/certs/webgpt.ancientrees.com/cert.pem \ --reloadcmd "service nginx force-reload" vim /etc/nginx/conf.d/webgpt.ancientrees.com.conf server { listen 443 ssl; server_name webgpt.ancientrees.com; ssl_certificate /etc/nginx/certs/webgpt.ancientrees.com/cert.pem; ssl_certificate_key /etc/nginx/certs/webgpt.ancientrees.com/key.pem; location / { proxy_pass http://localhost:1002; proxy_set_header Host $host ; 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 ; } } server { listen 80; server_name webgpt.ancientrees.com; return 301 https://$server_name$request_uri ; } sudo systemctl restart nginx
2. 安装MariaDB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 sudo dnf update sudo dnf remove mysql mysql-server mysql-libs sudo dnf config-manager --disable mysql57-community sudo dnf install mariadb-server mariaDB -V sudo systemctl start mariadb sudo systemctl enable mariadb sudo mysql_secure_installation
mariaDB常用命令:
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 40 41 42 43 44 45 46 sudo dnf search mariadb sudo rpm -qa | grep mariadb sudo systemctl start mariadb sudo systemctl stop mariadb sudo systemctl restart mariadb sudo systemctl status mariadb sudo netstat -tulnp | grep mariadb sudo systemctl enable mariadb sudo systemctl disable mariadb mysql -u 用户名 -p CREATE USER '用户名' @'localhost' IDENTIFIED BY '密码' ; GRANT ALL PRIVILEGES ON *.* TO 'username' @'localhost' ; GRANT ALL PRIVILEGES ON database_name.* TO 'username' @'localhost' ; GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP ON database_name.* TO 'username' @'localhost' ; FLUSH PRIVILEGES; SELECT User, Host, authentication_string FROM mysql.user; SHOW DATABASES; CREATE DATABASE database_name; Ctrl + C
3. 安装PHP 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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 sudo dnf install php sudo dnf install php-mysqli sudo dnf install libpng-devel sudo dnf install libjpeg-turbo-devel sudo dnf install freetype-devel sudo dnf install php-gd sudo systemctl start php-fpm sudo systemctl enable php-fpm vim /etc/nginx/conf.d/example.com.conf server { listen 81; server_name example.com; root /var/www/html; index index.php index.html index.htm; location / { try_files $uri $uri / /index.php?$query_string ; } location ~ \.php$ { try_files $uri =404; fastcgi_pass unix:/run/php-fpm/www.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name ; include fastcgi_params; } } vim /var/www/html/index.php <?php echo phpinfo();?>
php常用命令:
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 dnf module list php php -v rpm -qa | grep php php -m systemctl status php-fpm sudo systemctl start php-fpm sudo systemctl stop php-fpm sudo systemctl restart php-fpm sudo systemctl enable php-fpm sudo systemctl disable php-fpm sudo systemctl restart nginx sudo systemctl restart php-fpm