nginx静态配置

简介: nginx静态配置

环境Centos7.6
Nginx版本nginx version: nginx/1.20.1
1.直接用yum安装nginx,如果有需要自己编译即可

yum install -y nginx

2.改nginx.conf文件,默认放在etc下的nginx目录,配置文件详解请参考Nginx详解

vim /etc/nginx/nginx.conf
#下面的都是配置文件,可以直接复制替换掉原来的
user nginx;
worker_processes  2;
worker_cpu_affinity auto;
worker_rlimit_nofile 65535;
pid        /var/run/nginx.pid;
events {
    use  epoll;
    worker_connections  65535;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
     log_format mains $server_name "|" $remote_addr "|" [$time_iso8601] "|" "$request"  "|"
$status  "|" $body_bytes_sent "|"  "$http_referer"   "|"
"$http_user_agent"  "|"  $upstream_addr "|" $request_time   "|" $upstream_response_time|;
   client_max_body_size 100M;
   client_body_buffer_size 1024k;
   client_header_buffer_size 32k; 
   sendfile        on;
   gzip on;
   tcp_nopush     on;
   keepalive_timeout  300;
   proxy_connect_timeout    300;
   proxy_send_timeout     300;
   proxy_read_timeout     300;
   proxy_ignore_client_abort on;
   gzip_min_length 1k;
   gzip_buffers 4 16k;
   gzip_comp_level 2;
   gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
   gzip_disable "MSIE [1-6]\."; 
   gzip_vary off;
   include /etc/nginx/conf.d/http/*.conf;#这是你静态配置文件的目录文件地址,自己想换啥就换啥
    }

3.修改好了用nginx检查命令看一下啊是否OK

nginx -t
nginx -s reload

4.去include的地址新建一个目录和.conf配置文件

mkdir -p /etc/nginx/conf.d/http
cd /etc/nginx/conf.d/http/
vim www.ceshi.com.conf
#导入以下配置
server {
listen 80; #nginx监听的端口
server_name localhost; #配置网站域名,没有域名就是本机地址
location / {
  root /tmp/site;#静态页面存放路径
  index index.html index.htm;
}
}
mkdir -p /tmp/site
cd /tmp/site
echo hello world > index.html

5.再次用nginx命令检查一下,有异常就看nginx 的日志,把报错放百度

nginx -t
nginx -s reload

启动nginx,设置默认开机自启,查看nginx启动状态

systemctl start nginx
systemctl enable nginx
systemctl status nginx

然后复制你的本机的ip地址到浏览器打开,默认是80端口,我这边静态目录设置了是hello world,有可能是403页面,或者404,具体情况检查一下自己的配置文件和nginx的端口是否被占用,配置文件是否有漏符号。
6.nginx一键配置辅助工具nginx一键配置辅助工具

相关文章
|
9天前
|
应用服务中间件 Linux nginx
Jetson 环境安装(四):jetson nano配置ffmpeg和nginx(亲测)之编译错误汇总
这篇文章是关于在Jetson Nano上配置FFmpeg和Nginx时遇到的编译错误及其解决方案的汇总。
46 4
|
5天前
|
缓存 负载均衡 安全
Nginx常用基本配置总结:从入门到实战的全方位指南
Nginx常用基本配置总结:从入门到实战的全方位指南
112 0
|
10天前
|
编解码 Ubuntu 应用服务中间件
Jetson 环境安装(三):jetson nano配置ffmpeg和nginx(亲测)
本文介绍了在NVIDIA Jetson Nano上配置FFmpeg和Nginx的步骤,包括安装、配置和自启动设置。
69 1
Jetson 环境安装(三):jetson nano配置ffmpeg和nginx(亲测)
|
4天前
|
前端开发 JavaScript 应用服务中间件
终极 Nginx 配置指南
本文介绍了Nginx的基本配置及其优化方法。首先,通过删除注释简化了Nginx的默认配置文件,使其更易于理解。接着,文章将Nginx配置文件分为全局块、events块和http块三部分进行详细解释。此外,还提供了如何快速上线网站、解决前端history模式404问题、配置反向代理、开启gzip压缩、设置维护页面、在同一IP上部署多个网站以及实现动静分离的具体配置示例。最后,附上了Nginx的基础命令,包括安装、启动、重启和关闭等操作。
|
8天前
|
负载均衡 应用服务中间件 nginx
Nginx的6大负载均衡策略及权重轮询手写配置
【10月更文挑战第9天】 Nginx是一款高性能的HTTP服务器和反向代理服务器,它在处理大量并发请求时表现出色。Nginx的负载均衡功能可以将请求分发到多个服务器,提高网站的吞吐量和可靠性。以下是Nginx支持的6大负载均衡策略:
33 7
|
10天前
|
缓存 前端开发 应用服务中间件
CORS跨域+Nginx配置、Apache配置
CORS跨域+Nginx配置、Apache配置
49 7
|
6天前
|
缓存 前端开发 JavaScript
一、nginx配置
一、nginx配置
51 1
|
15天前
|
存储 缓存 监控
|
16天前
|
安全 应用服务中间件 Shell
nginx配置https的ssl证书和域名
nginx配置https的ssl证书和域名
|
16天前
|
存储 缓存 前端开发
理清 nginx 中的 location 配置
理清 nginx 中的 location 配置