LNMP环境搭建:Nginx编译安装
1.安装 nginx
- 安装编译所需功能
yum -y install gcc gcc- c++ wget vim
- 下载nginx文件包, 下载地址:http://nginx.org
## 下载nginx安装包,版本根据自己需求自己替换,
wget http://nginx.org/download/nginx-1.16.1.tar.gz
## 解压缩
tar -xvf nginx-1.10.3.tar.gz
## 进入解压后的目录
cd nginx-1.10.3
- 安装
## 安装nginx所需功能
yum install -y pcre-devel openssl openssl-devel
## 配置信息,--prefix为安装文件的目录
./configure --prefix=/usr/local/nginx \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-threads --with-stream \
--with-stream_ssl_module \
--with-http_slice_module --with-mail \
--with-mail_ssl_module --with-file-aio \
--with-http_v2_module --with-ipv6 \
--with-pcre \
## 编译和安装
make && make install
4.设置开机启动
## 将nginx加入到systemctl中
vi /usr/lib/systemd/system/nginx.service
## 配置信息
[Unit]
Description=nginx.service
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
- nginx 基础配置 – 引入 vhost 配置,虚拟目录,强烈推荐!
## 在nginx配置路径中建立vhost文件夹,/usr/local/nginx/conf
mkdir vhost
## 配置nginx.conf,路径/usr/local/nginx/conf
vim nginx.conf
## 在http{末尾加入}
include vhost/*.conf
- vhost 配置
server {
listen 80;
server_name local.laravel.com;
root /data/www/laravel/public;
location / {
index index.html index.htm index.php;
try_files $uri $uri/ /index.php$is_args$query_string; #laravel除了首页其他全404增加这句
if (!-e $request_filename){
rewrite ^/(.*)$ /index.php/$1 last;
}
}
location ~ \.php($|/) {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$; #增加这一句
fastcgi_param PATH_INFO $fastcgi_path_info; #增加这一句
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
1、开启80端口命令:/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
2、保存配置 命令:/etc/rc.d/init.d/iptables save
3、重启服务命令 :/etc/rc.d/init.d/iptables restart
4、查看已经开放的端口: /etc/init.d/iptables status
5、Centos8 需要关闭自带的防火墙 `systemctl stop firewalld `
7.1 各种重定向配置
server {
listen 80;
server_name dev.test.com;
listen 443;
ssl on;
index index.html index.htm;
ssl_certificate ../conf/cert/dev.bayinyq.com.pem;
ssl_certificate_key ../conf/cert/dev.bayinyq.com.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
#登录绑定相关
location /account{
proxy_pass http://127.0.0.1:8181;
}
#app
location /app{
proxy_pass http://127.0.0.1:8184;
}
location /exampledemo{
#subs_filter "login/" "";
#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_pass http://127.0.0.1:8081;
index index.html index.htm;
}
}
server {
listen 8184;
root /usr/local/nginx/html/app/public;
location / {
index index.html index.htm index.php;
autoindex on;
if (!-e $request_filename){
rewrite ^/(.*)$ /index.php/$1 last;
}
}
location ~ \.php($|/) {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
if ($uri ~ "^(.+\.php)(/app-parent)(/.*)") {
set $script $1;
set $module $2;
set $path_info $3;
}
fastcgi_param PATH_INFO $path_info;
fastcgi_param SCRIPT_FILENAME $document_root$script; #php的执行脚本
include fastcgi_params;
}
}
最后打个广告:
Crmeb多商户版是基于ThinkPhp6+ swoole4+uniapp 开发的一套CRMEB新零售多商户商城系统。集客户关系管理+营销电商系统,能够真正帮助企业基于微信公众号、小程序、wap、pc等,实现会员管理、数据分析,精准营销的电子商务管理系统。可满足企业新零售、批发、分销、预约、O2O、多店、商铺入驻等各种业务需求。
演示站 : http://github.crmeb.net/u/xian 账号:demo 密码:crmeb.com