CentOS7 使用java建站程序publiccms建站教程之--Redhat系环境配置篇
本篇主要讲解nginx、tomcat、mysql的详细配置,相信很多人也跟本站长一样,在centos内配置环境又没有基础的情况下简直是抓虾。在经历各种摸黑滚打之后,站长已经在配置环境方面有一定的专长,尤其擅长nginx、php、tomcat、mysql等方面的配置和维护。不卖瓜了开始讲解,为了给同样刚开始接触建站的新人一点帮助。
在讲解配置前的工作:
1、 确定selinux已关闭
2、 开启80端口、443端口、8080端口
3、 配置ssh无密码证书登录 //这项可以省略,本地无所谓
4、 检测nginx、tomcat、mariadb是否已安装。如未安装,请看上一篇内容《环境搭建篇》
一、tomcat配置
安装jre
yum install jre –y
查看jre版本
java -version
进入tomcat配置文件目录
cd /usr/local/tomcat/conf/
备份server.xml文件
cp server.xml server.xml.bak
编辑server.xml文件
vi server.xml
修改/opt/website/的路径,这个路径是你放置站点的路径,请仔细设置
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"> <Context path="" docBase="/opt/website/" debug="0" reloadable="true"></Context> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log" suffix=".txt" pattern="%h %l %u %t "%r" %s %b" /> </Host>
按ESC键,wq保存退出,在不开启https的情况下,tomcat配置完成。关于配置https项以后会讲。
二、nginx配置
nginx配置给出的写入案例,均是经过优化和官方建议的,可以根据自己的需求自行修订
进入nginx目录
cd /etc/nginx/
备份nginx.conf文件
cp nginx.conf nginx.conf.bak
配置nginx.conf文件
vi nginx.conf
写入以下内容到nginx.conf 文件
# For more information on configuration, see: # * Official English Documentation: http://nginx.org/en/docs/ # * Official Russian Documentation: http://nginx.org/ru/docs/ user nginx; worker_processes auto; error_log /var/log/nginx/error.log; pid /run/nginx.pid; # Load dynamic modules. See /usr/share/nginx/README.dynamic. include /usr/share/nginx/modules/*.conf; events { worker_connections 1024; } http { log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; client_header_buffer_size 32k; large_client_header_buffers 4 32k; sendfile on; tcp_nopush on; tcp_nodelay on; server_tokens off; keepalive_timeout 60; types_hash_max_size 2048; client_max_body_size 8M; gzip on; gzip_vary on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.0; gzip_comp_level 2; gzip_disable "MSIE [1-6]\."; gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png; include /etc/nginx/mime.types; default_type application/octet-stream; # Load modular configuration files from the /etc/nginx/conf.d directory. # See http://nginx.org/en/docs/ngx_core_module.html#include # for more information. include /etc/nginx/conf.d/*.conf; }
进入conf目录
cd conf
创建网站需要的conf文件
vi site.conf
写入以下内容到site.conf文件,此写入方式是未开启https的写法
upstream cms { server localhost:8080 weight=1; } server { listen 80; server_name www.rednn.com; location / { alias /opt/website/web/site_1/; index index.html; add_header Access-Control-Allow-Origin *; } } server { listen 80; server_name cms.rednn.com search.rednn.com; location / { proxy_redirect off; 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_connect_timeout 5; proxy_send_timeout 30; proxy_read_timeout 10; proxy_pass http://cms; } location /webfile/ { alias /opt/website/web/site_1/webfile/; index index.html; } location /include/ { alias /opt/website/web/site_1/include/; } }
重启nginx
systemctl restart nginx.service
三、mariadb/mysql配置
配置数据库编码,关于数据库编码怎样选择的问题,请自行查档。本站采用utf8mb4_unicode_ci编码,也推荐使用这个。
编辑或创建vi /etc/my.cnf文档,修改utf8mb4_unicode_ci默认编码。
vi /etc/my.cnf
拷贝以下内容到my.cnf
[client] default-character-set=utf8mb4 [mysql] default-character-set=utf8mb4 [mysqld] collation-server = utf8mb4_unicode_ci init-connect='SET NAMES utf8mb4' character-set-server = utf8mb4
重启mariadb
Systemctl restart mariadb
到此,环境已经配置完成
已获取点赞 +0
评论 点击评论