nginx静态配置&安装

少年辛苦终身事,莫向光阴惰寸功。这篇文章主要讲述nginx静态配置&安装相关的知识,希望能为你提供帮助。

systemctl start nginx#启动 systemctl enable nginx #默认开机自启 systemctl status nginx #查看启动状态 nginx -t #检查配置是否正确 nginx -s reload #重新加载配置 ps -ef|grep 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_processes8; ###线程数 worker_cpu_affinity auto; worker_rlimit_nofile 65535; pid/var/run/nginx.pid; events useepoll; worker_connections65535; http includemime.types; default_typeapplication/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; sendfileon; gzip on; tcp_nopushon; keepalive_timeout300; proxy_connect_timeout300; proxy_send_timeout300; proxy_read_timeout300; 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子配置文件/etc/nginx/conf.d/http/*.conf
[root@localhost http]# pwd /etc/nginx/conf.d/http [root@localhost http]# ll 总用量 4 -rw-r--r--. 1 root root 98 5月12 00:59 xiao.conf [root@localhost http]# cat xiao.conf server listen80; location/ root/opt/static ; indexindex.html; [root@localhost http]#

写入以下内容
server listen80; location/ root/opt/static ; indexindex.html;

【nginx静态配置&安装】==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]# viindex.html

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

    推荐阅读