在nginx主配置文件nginx.conf的http模块下引入配置文件夹(注意路径的正确性)

 

1、nginx主配置文件备份后编辑(nginx配置存放位置:/usr/local/nginx/conf/):

cd /usr/local/nginx/conf/ && mv nginx.conf nginx.conf-bak && vim nginx.conf

贴入内容如下:

user www www; #运行用户
worker_processes 1; #设置值和CPU核心数一致
error_log /usr/local/nginx/logs/nginx_error.log crit; #错误日志位置和日志级别
pid /usr/local/nginx/nginx.pid; #目录和安装位置一致才行,按教程安装的不用改目录
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65535;
events
{
  use epoll;
  worker_connections 65535;
}
http
{

  include /usr/local/nginx/conf/conf.d/*.conf;
  #这里就是引入的子配置文件夹
  include mime.types;
  default_type application/octet-stream;
  log_format main  '$remote_addr - $remote_user [$time_local] "$request" '
               '$status $body_bytes_sent "$http_referer" '
               '"$http_user_agent" $http_x_forwarded_for';
  
#charset gb2312;
     
  server_names_hash_bucket_size 128;
  client_header_buffer_size 32k;
  large_client_header_buffers 4 32k;
  client_max_body_size 8m;
     
  sendfile on;
  tcp_nopush on;
  keepalive_timeout 60;
  tcp_nodelay on;
  fastcgi_connect_timeout 300;
  fastcgi_send_timeout 300;
  fastcgi_read_timeout 300;
  fastcgi_buffer_size 64k;
  fastcgi_buffers 4 64k;
  fastcgi_busy_buffers_size 128k;
  fastcgi_temp_file_write_size 128k;
  gzip on; 
  gzip_min_length 1k;
  gzip_buffers 4 16k;
  gzip_http_version 1.0;
  gzip_comp_level 2;
  gzip_types text/plain application/x-javascript text/css application/xml;
  gzip_vary on;

}


2、在引入的配置文件夹中添加个基础的独立配置文件html.conf,

复制用快捷指令:mkdir /usr/local/nginx/conf/conf.d/ && cd /usr/local/nginx/conf/conf.d/ && vim html.conf

贴入下方绿色文字配置:

server
  {
    listen 80;#监听端口
    server_name localhost;#域名
    index index.html index.htm index.php;
    root /usr/local/nginx/html; #站点目录,要存在,没有的话手动创建个目录,不然报错
      location ~ .*.(php|php5)?$
    {
      #fastcgi_pass unix:/tmp/php-cgi.sock;
      fastcgi_pass 127.0.0.1:9000;
      fastcgi_index index.php;
      include fastcgi.conf;
    }
    location ~ .*.(gif|jpg|jpeg|png|bmp|swf|ico)$
    {
      expires 30d;
  # access_log off;
    }
    location ~ .*.(js|css)?$
    {
      expires 15d;
   # access_log off;
    }
    access_log off;
  }

 

3、配置检查

cd /usr/local/nginx/sbin && ./nginx -t

 

4、启动nginx

cd /usr/local/nginx/sbin && ./nginx

 

nginx运行状态查看

查看80端口占用情况:
netstat -tunlp | grep 80

# 查看进程是否运行
ps -A | grep nginx

# 强制关闭nginx
pkill nginx

内容来源于网络如有侵权请私信删除

文章来源: 博客园

原文链接: https://www.cnblogs.com/brad93/p/16647499.html

你还没有登录,请先登录注册
  • 还没有人评论,欢迎说说您的想法!

相关课程