Linux系统下安装配置Nginx环境整理
发布:smiling 来源: PHP粉丝网 添加日期:2015-05-05 15:47:00 浏览: 评论:0
安装Nginx是做WEB服务器的一个选项之一了,如果网站静态多我们多半使用nginx否则会选择apache了,下面我们不说远了就来看看Linux系统下安装配置Nginx环境整理吧.
PHP的这些环境在linux下也折腾过很多次了,每次重装都要重新去找这些文档,记性不好,还是自己整理下吧.
Nginx安装:
- # yum -y install gcc* pcre glib2-devel openssl-devel pcre-devel bzip2-devel gzip-devel lrzsz
- # groupadd www && useradd www -g www
- # wget http://nginx.org/download/nginx-1.6.1.tar.gz
- # tar zxvf nginx-1.6.1.tar.gz
- # cd nginx-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 && make install
机器为阿里云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 -s reload ' >> /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 -s reload
- nginx.conf
配置示例,通过vhost来配置新站点,避免nginx.conf文件过长,不方便管理.
- # more /root/nginx.conf
- user www www;
- worker_processes 1;
- error_log logs/error.log;
- pid logs/nginx.pid;
- events {
- use epoll;
- worker_connections 1024;
- }
- http {
- <a href="/tags.php/include/" target="_blank">include</a> mime.types;
- default_type application/octet-stream;
- server_names_hash_bucket_size 128;
- client_header_buffer_size 32k;
- large_client_header_buffers 4 32k;
- client_max_body_size 50m;
- log_format main '$remote_addr - $remote_user [$time_local] "$<a href="/tags.php/request/" target="_blank">request</a>" '
- '$status $body_bytes_sent "$http_referer" '
- '"$http_user_agent" "$http_x_forwarded_for"';
- 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-<a href="/js_a/js.html" target="_blank">javascript</a> text/css application/xml;
- gzip_vary on;
- include vhost/*.conf;
- }
添加80端口:
- server {
- listen 80;
- server_name localhost;
- index index.htm index.html index.php;
- --phpfensi.com
- root /data/www;
- access_log /data/logs/nginx/default.access.log;
- }
Tags: 配置Nginx Linux环境
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)