0
点赞
收藏
分享

微信扫一扫

nginx静态配置&安装

1.安装

yum -y install nginx
若这一步报错 证明我们的yum源里没有此安装包 需要配置安装包
cd /etc/yum.repos.d/
vi nginx.repo
写入一下内容
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1

2.配置 /etc/nginx/nginx.conf 文件

写入一下内容

user nginx;
worker_processes  8;   ###线程数
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;    ### 子配置文件
    }

==nginx -t 检查配置是否正确==

[root@localhost http]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

5.新建include子配置文件

写入以下内容
server  {
  listen   80;
  location  / {
     root  /opt/static ;
     index  index.html;
    }
}

==nginx -t 检查配置是否正确==

6.配置静态页面地址

[root@localhost ~]#  mkdir -p /opt/static
[root@localhost http]# cd /opt/static
[root@localhost static]# ll
total 4
-rw-r--r--. 1 root root 29 Apr 12 13:21 index.html
[root@localhost static]# vi  index.html

检查配置是否正确
nginx -t ###检查语法
nginx -s reload ###重新加载配置
ps -ef|grep nginx ###查看进程

举报

相关推荐

0 条评论