thlm0 2020-04-16
VMware Workstation 15.5 平台
CentOS 7 64bit
(1)开启虚拟机,使用root账户登陆
(2)更新yum源。
yum -y update
vim /etc/yum.repos.d/nginx.repo
[nginx] name = nginx repo baseurl = https://nginx.org/packages/mainline/centos/7/$basearch/ gpgcheck = 0 enabled = 1
yum install -y nginx
vim /etc/nginx/nginx.conf#打开配置文件
找到 server{...}
,并将 server
大括号中相应的配置信息替换为如下内容。用于取消对 IPv6 地址的监听,同时配置 Nginx,实现与 PHP 的联动。
server { listen 80; root /usr/share/nginx/html; server_name localhost; #charset koi8-r; #access_log /var/log/nginx/log/host.access.log main; # location / { index index.php index.html index.htm; } #error_page 404 /404.html; #redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } #pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ .php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
若 nginx.conf
文件中未找到 server{...}
,请在 include /etc/nginx/conf.d/*conf;
上方进行添加。
systemctl start nginx systemctl enable nginx
使用ifconfig查看一下当前的IP地址,然后再物理机浏览器地址栏输入:http://[你的IP地址]
如果打不开,有可能是防火墙的问题,我们执行下面的命令开启防火墙的80(http)和443(https)端口。
firewall-cmd --permanent --zone=public --add-service=http firewall-cmd --permanent --zone=public --add-service=https firewall-cmd --reload
然后我们再次打开,如果看到“Welcome to Nginx!...”,说明我们安装成功。
vi /etc/yum.repos.d/MariaDB.repo
# MariaDB 10.4 CentOS repository list - created 2019-11-05 11:56 UTC # http://downloads.mariadb.org/mariadb/repositories/ [mariadb] name = MariaDB baseurl = http://yum.mariadb.org/10.4/centos7-amd64 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1
yum -y install MariaDB-client MariaDB-server
systemctl start mariadb systemctl enable mariadb
mysql
rpm -Uvh https://mirrors.cloud.tencent.com/epel/epel-release-latest-7.noarch.rpm rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum -y install mod_php72w.x86_64 php72w-cli.x86_64 php72w-common.x86_64 php72w-mysqlnd php72w-fpm.x86_64
systemctl start php-fpm systemctl enable php-fpm
(1)创建测试文件
echo "<?php phpinfo(); ?>" >> /usr/share/nginx/html/index.php
(2)重启 Nginx 服务
systemctl restart nginx
(3)访问:http://[IP地址]/index.php
rpm -qa | grep jdk
mkdir /usr/local/java/
(1)通过Xftp将下载的jdk-8u251-linux-x64.tar.gz传到/usr/local/java
(2)进入/usr/local/java解压到当前文件夹
cd /usr/local/java tar -zxvf jdk-8u251-linux-x64.tar.gz
(1)打开配置文件
vim /etc/profile
(2)在文件末尾添加以下语句
export JAVA_HOME=/usr/local/java/jdk1.8.0_251 export JRE_HOME=${JAVA_HOME}/jre export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib export PATH=${JAVA_HOME}/bin:$PATH
(3)使环境变量生效
source /etc/profile
java -version
前往tomcat官网下载对用的版本,我们选择Core->tar.gz进行下载
在/usr/local下新建一个文件夹,命名为tomcat
mkdir /usr/local/tomcat
(1)通过Xftp将下载的apache-tomcat-9.0.34-src.tar.gz传到/usr/local/tomcat
(2)进入/usr/local/tomcat解压到当前文件夹
cd /usr/local/tomcat tar -zxvf apache-tomcat-9.0.34-src.tar.gz
(3)将解压后的文件夹重命名为tomcat1
mv ./apache-tomcat-9.0.34 ./tomcat1
/usr/local/tomcat/tomcat1/bin/startup.sh
server.xml可以配置端口,编码以及配置项目等等,配置端口把默认的8080,修改成8081
vim /usr/local/tomcat/tomcat2/conf/server.xml
修改红框内的东西
/usr/local/tomcat/tomcat2/bin/startup.sh
注意:
我们需要先关闭SeLinux。
#临时关闭,不需要重启 setenforce 0 #永久关闭,需要重启 修改/etc/selinux/config 文件 将SELINUX=enforcing改为SELINUX=disabled 重启机器即可
(1)编辑Nginx配置文件
vim /etc/nginx/nginx.conf
(2)添加红框内的语句,每个人按照自己的环境进行配置
(3)保存退出,重启Nginx服务
systemctl restart nginx
(4)验证
http://www.dj024.com/user/57801.html
http://www.dj024.com/user/57803.html
http://www.dj024.com/user/57805.html
http://www.dj024.com/user/57806.html
http://www.dj024.com/user/57809.html
http://www.dj024.com/user/57795.html
http://www.dj024.com/user/57797.html
http://www.dj024.com/user/57798.html
某些公司会墙特定网站,如果你有一个可访问的域名和服务器,就可以通过nginx反向代理来来解决这些问题。比如现在我们用mirror.example.com镜像www.baidu.com,以下是详细操作。