LNMP 架构指的是 Linux、Nginx、MySQL 和 PHP 这四种技术的组合,常用于搭建网站服务器。在 LNMP 架构中,Nginx 作为 Web 服务器,负责处理 HTTP 请求。以下是 Nginx 的基本配置步骤和配置文件结构:
yum -y install make automake autoconf libtool zlib zlib-devel gcc gcc-c++ openssl openssl-devel
cd /usr/local/src/
wget http://ftp.pcre.org/pub/pcre/pcre-8.35.tar.gz
tar zxvf pcre-8.35.tar.gz
cd pcre-8.35
./configure
make && make install
pcre-config --version
cd /usr/local/src/
wget http://nginx.org/download/nginx-1.14.0.tar.gz
tar zxvf nginx-1.14.0.tar.gz
cd nginx-1.14.0
./configure --prefix=/usr/local/nginx \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--http-client-body-temp-path=/var/tmp/nginx/client \
--http-proxy-temp-path=/var/tmp/nginx/proxy \
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi \
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
--http-scgi-temp-path=/var/tmp/nginx/scgi \
--with-pcre \
--with-http_v2_module \
--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-mail \
--with-mail_ssl_module \
--with-file-aio \
--with-threads \
--with-stream \
--with-stream_ssl_module \
--with-ipv6
make && make install
Nginx 配置文件(通常命名为 nginx.conf)位于 Nginx 安装目录的 conf 目录下,其整体结构如下:
以下是一个简单的 Nginx 配置文件示例:
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
}
在配置 Nginx 时,通常需要根据实际需求调整上述配置,例如设置监听端口、服务器名称、网站根目录等。此外,还可能需要配置 HTTPS、负载均衡、缓存等功能,这些高级配置超出了基本配置的范围,但可以通过 Nginx 的官方文档和相关教程来学习。