安装Nginx是做WEB服务器的一个选项之一了,如果网站静态多我们多半使用nginx否则会选择apache了,下面我们不说远了就来看看Linux系统下安装配置Nginx环境整理吧.
PHP的这些环境在linux下也折腾过很多次了,每次重装都要重新去找这些文档,记性不好,还是自己整理下吧.
Nginx安装:
- #yum-yinstallgcc*pcreglib2-developenssl-develpcre-develbzip2-develgzip-devellrzsz
- #groupaddwww&&useraddwww-gwww
- #wgethttp://nginx.org/download/nginx-1.6.1.tar.gz
- #tarzxvfnginx-1.6.1.tar.gz
- #cdnginx-1.6.1
- #./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
- #make&&makeinstall
机器为阿里云512MCentOS,刚初始化的机器发现没有make命令,通过yum安装即可.
# yum -y install make
常用操作:
- --root软连接到nginx.conf
- #ln-s/usr/local/webserver/nginx/conf/nginx.conf/root/nginx.conf
- --root目录下直接重启脚本
- #echo-e'#!/bin/bash\n/usr/local/webserver/nginx/sbin/nginx-sreload'>>/root/nginx_restart.sh
- --添加执行权限
- #chmod+x/root/nginx_restart.sh
- --添加到自启动
- #echo'/usr/local/webserver/nginx/sbin/nginx'>>/etc/rc.local
启动Nginx:
- #/usr/local/webserver/nginx/sbin/nginx
- --检测是否配置文件是否正确
- #/usr/local/webserver/nginx/sbin/nginx-t
- --重启nginx
- #/usr/local/webserver/nginx/sbin/nginx-sreload
- nginx.conf
配置示例,通过vhost来配置新站点,避免nginx.conf文件过长,不方便管理.
- #more/root/nginx.conf
- userwwwwww;
- worker_processes1;
- error_loglogs/error.log;
- pidlogs/nginx.pid;
- events{
- useepoll;
- worker_connections1024;
- }
- http{
- <ahref="/tags.php/include/"target="_blank">include</a>mime.types;
- default_typeapplication/octet-stream;
- server_names_hash_bucket_size128;
- client_header_buffer_size32k;
- large_client_header_buffers432k;
- client_max_body_size50m;
- log_formatmain'$remote_addr-$remote_user[$time_local]"$<ahref="/tags.php/request/"target="_blank">request</a>"'
- '$status$body_bytes_sent"$http_referer"'
- '"$http_user_agent""$http_x_forwarded_for"';
- sendfileon;
- tcp_nopushon;
- keepalive_timeout60;
- tcp_nodelayon;
- fastcgi_connect_timeout300;
- fastcgi_send_timeout300;
- fastcgi_read_timeout300;
- fastcgi_buffer_size64k;
- fastcgi_buffers464k;
- fastcgi_busy_buffers_size128k;
- fastcgi_temp_file_write_size128k;
- gzipon;
- gzip_min_length1k;
- gzip_buffers416k;
- gzip_http_version1.0;
- gzip_comp_level2;
- gzip_typestext/plainapplication/x-<ahref="/js_a/js.html"target="_blank">javascript</a>text/cssapplication/xml;
- gzip_varyon;
- includevhost/*.conf;
- }
添加80端口:
- server{
- listen80;
- server_namelocalhost;
- indexindex.htmindex.htmlindex.php;
- --phpfensi.com
- root/data/www;
- access_log/data/logs/nginx/default.access.log;
- }