Linux系统下安装配置Nginx环境整理

SEO探索者团队 SEO服务&网站优化

安装Nginx是做WEB服务器的一个选项之一了,如果网站静态多我们多半使用nginx否则会选择apache了,下面我们不说远了就来看看Linux系统下安装配置Nginx环境整理吧.

PHP的这些环境在linux下也折腾过很多次了,每次重装都要重新去找这些文档,记性不好,还是自己整理下吧.

Nginx安装:

  1. #yum-yinstallgcc*pcreglib2-developenssl-develpcre-develbzip2-develgzip-devellrzsz
  2. #groupaddwww&&useraddwww-gwww
  3. #wgethttp://nginx.org/download/nginx-1.6.1.tar.gz
  4. #tarzxvfnginx-1.6.1.tar.gz
  5. #cdnginx-1.6.1
  6. #./configure--user=www--group=www--prefix=/usr/local/webserver/nginx--with-http_stub_status_module--with-http_ssl_module--error-log-path=/data/logs/nginx/error.log--http-log-path=/data/logs/nginx/access.log
  7. #make&&makeinstall

机器为阿里云512MCentOS,刚初始化的机器发现没有make命令,通过yum安装即可.

# yum -y install make

常用操作:

  1. --root软连接到nginx.conf
  2. #ln-s/usr/local/webserver/nginx/conf/nginx.conf/root/nginx.conf
  3. --root目录下直接重启脚本
  4. #echo-e'#!/bin/bash\n/usr/local/webserver/nginx/sbin/nginx-sreload'>>/root/nginx_restart.sh
  5. --添加执行权限
  6. #chmod+x/root/nginx_restart.sh
  7. --添加到自启动
  8. #echo'/usr/local/webserver/nginx/sbin/nginx'>>/etc/rc.local

启动Nginx:

  1. #/usr/local/webserver/nginx/sbin/nginx
  2. --检测是否配置文件是否正确
  3. #/usr/local/webserver/nginx/sbin/nginx-t
  4. --重启nginx
  5. #/usr/local/webserver/nginx/sbin/nginx-sreload
  6. nginx.conf

配置示例,通过vhost来配置新站点,避免nginx.conf文件过长,不方便管理.

  1. #more/root/nginx.conf
  2. userwwwwww;
  3. worker_processes1;
  4. error_loglogs/error.log;
  5. pidlogs/nginx.pid;
  6. events{
  7. useepoll;
  8. worker_connections1024;
  9. }
  10. http{
  11. <ahref="/tags.php/include/"target="_blank">include</a>mime.types;
  12. default_typeapplication/octet-stream;
  13. server_names_hash_bucket_size128;
  14. client_header_buffer_size32k;
  15. large_client_header_buffers432k;
  16. client_max_body_size50m;
  17. log_formatmain'$remote_addr-$remote_user[$time_local]"$<ahref="/tags.php/request/"target="_blank">request</a>"'
  18. '$status$body_bytes_sent"$http_referer"'
  19. '"$http_user_agent""$http_x_forwarded_for"';
  20. sendfileon;
  21. tcp_nopushon;
  22. keepalive_timeout60;
  23. tcp_nodelayon;
  24. fastcgi_connect_timeout300;
  25. fastcgi_send_timeout300;
  26. fastcgi_read_timeout300;
  27. fastcgi_buffer_size64k;
  28. fastcgi_buffers464k;
  29. fastcgi_busy_buffers_size128k;
  30. fastcgi_temp_file_write_size128k;
  31. gzipon;
  32. gzip_min_length1k;
  33. gzip_buffers416k;
  34. gzip_http_version1.0;
  35. gzip_comp_level2;
  36. gzip_typestext/plainapplication/x-<ahref="/js_a/js.html"target="_blank">javascript</a>text/cssapplication/xml;
  37. gzip_varyon;
  38. includevhost/*.conf;
  39. }

添加80端口:

  1. server{
  2. listen80;
  3. server_namelocalhost;
  4. indexindex.htmindex.htmlindex.php;
  5. --phpfensi.com
  6. root/data/www;
  7. access_log/data/logs/nginx/default.access.log;
  8. }

相关广告
  • Linux系统下安装配置Nginx环境整理 Linux系统下安装配置Nginx环境整理 Linux系统下安装配置Nginx环境整理
相关阅读

Linux系统下安装配置Nginx环境整理

2019/10/10 17:45:04 | 谷歌SEO算法 | 5G标准出炉