1. 配置LNMP,并部署php应用。
L Linux(centos7)
N nginx
M MySQL(mariadb)
P php
具有成本低廉、部署灵活、快速开发、安全稳定等特点,是 Web 网络应用和环境的优秀组合。若是服务器配置比较低的个人网站,首选 LNMP。
安装nginx,mariadb,php
nginx linux 安装并配置nginx
mariadb,php
yum install nginx mariadb-server php php-mysql php-gd php-fpm -y
systemctl enable mariadb --now(开启)mysqladmin -uroot password ‘(密码)’
vim /etc/my.cnf
添加character-set-server=utf8
更改nginx配置文件(/usr/local/nginx/conf/nginx.conf)
server {
listen 8084;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.php index.html index.htm;
}
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php/$1 last;
}
location ~ .*\.php(\/.*)*$ {
fastcgi_pass 127.0.0.1:9000;
include fastcgi.conf;
fastcgi_index index.php;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
echo "<?php phpinfo(); ?>" >/usr/local/nginx/html/test.php
重启nginx,mariadb,php-fpm
systemctl restart nginx mariadb php-fpm
测试
2. 配置nginx反向代理。
环境:tomcat、nginx
安装方法:tomcat linux安装tomcat
nginx linux 安装并配置nginx
启动tomcat及nginx
启动tomcat(/usr/local/tomcat/bin/startup.sh)
启动nginx(systemctl start nginx)
修改nginx配置文件
(vim /usr/local/nginx/conf/nginx.conf)
如下配置,Nginx监听80端口,访问192.168.40.146(不加端口号时默认为80端口),故访问该域名时会跳转到192.168.40.146:8080(tomcat网页)路径上。
nginx 反向代理服务监听192.168.40.146的80端口,有请求过来时,转到proxy_pass配置的对应端口上
测试