【nginx】中server配置说明

server {
  listen       80;  //监听的端口号
  server_name  localhost;  //用域名方式访问的地址

  #charset koi8-r; //编码
  #access_log  /var/log/nginx/host.access.log  main;  //访问日志文件和名称

  location / {
      root   /usr/share/nginx/html;  //静态文件根目录
      index  index.html index.htm;  //首页的索引文件
  }

  #error_page  404              /404.html;  //指定错误页面

  # redirect server error pages to the static page /50x.html
  # 把后台错误重定向到静态的50x.html页面
  error_page   500 502 503 504  /50x.html; 
   当路径是/50x.html去找/usr/share/nginx/html里面的文件
  location = /50x.html {
      root   /usr/share/nginx/html;
  }

  # proxy the PHP scripts to Apache listening on 127.0.0.1:80
  如果访问的是.php结尾会把请求转发给http://127.0.0.1;
  # 代理PHP脚本到80端口上的apache服务器
  值Apache服务器
  #location ~ \.php$ {
  #    proxy_pass   http://127.0.0.1;
  #}

  # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  # 把PHP脚本9000端口上监听的FastCGI服务
  执行时PHP服务器
  如果访问的是.php结尾会把请求转发给127.0.0.1:9000;
  #location ~ \.php$ {
  #    root           html;
  #    fastcgi_pass   127.0.0.1:9000;
  #    fastcgi_index  index.php;
  #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
  #    include        fastcgi_params;
  #}

  # deny access to .htaccess files, if Apache's document root
  # concurs with nginx's one
  # 不允许访问.htaccess文件
  #location ~ /\.ht {
  #    deny  all; 禁止所以人访问
  #}
}

// 重启
nginx -s reload
systenmctl reload nginx.service

// 验证
nginx -t

// 多级代理
http_x_forwarded_for 客户端代理IP1 代理IP2

  

猜你喜欢

转载自www.cnblogs.com/wuxianqiang/p/10705212.html