nginx配置指南

停止 nginx -s stop
启动 nginx 


配置 conf 下的nginx.conf 中的location->root 设置首页


安装nginx----------------------------------------------------------------------------------------
1.安装pcre (ubantu: apt-get install pcre \ centos:rpm -ivh pcre)
2.安装nginx (ubantu: apt-get install nginx \ centos:rpm -ivh nginx)
3.配置conf nginx.conf location->root
4.多配置 多个location /otherpath(~^ 等等)
详情可参考:http://www.runoob.com/linux/nginx-install-setup.html

nginx配置基本结构:http{ server{ location{ } } }

这里主要讲nginx的配置文件

user www-data;
worker_processes 4;
pid /run/nginx.pid;

events {
	worker_connections 768;#最大连接数
	# multi_accept on;
}

http {
	sendfile on;#是否支持文件下载
	tcp_nopush on;#tcp禁止推送
	tcp_nodelay on;#tcp禁止延时发送请求,一一回应,不采用打包发送的算法
	keepalive_timeout 65;#超时时间
	types_hash_max_size 2048;#文件上传大小MB
	# server_tokens off; #采用令牌方式

	# server_names_hash_bucket_size 64;#缓冲空间大小
	# server_name_in_redirect off;#是否开启重定向,重定向会自动解析Local>http://blog.youkuaiyun.com/weiyuefei/article/details/38556593

	include /etc/nginx/mime.types;#支持哪些方式访问
	default_type application/octet-stream;

	##
	# Logging Settings 日志系统
	##

	access_log /var/log/nginx/access.log;
	error_log /var/log/nginx/error.log;

	##
	# Gzip Settings 压缩支持
	##

	gzip on;
	gzip_disable "msie6";#对于IE6不压缩

	# gzip_vary on;#开启压缩缓存
	# gzip_proxied any;# 做前端代理时启用该选项,表示无论后端服务器的headers头返回什么信息,都无条件启用压缩
	# gzip_comp_level 6;#压缩级别,越小越快压缩效果越差
	# gzip_buffers 16 8k;#压缩流大小
	# gzip_http_version 1.1;#http协议版本
	# gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

	##
	# nginx-naxsi config
	##
	# Uncomment it if you installed nginx-naxsi
	##

	#include /etc/nginx/naxsi_core.rules;#防攻击的配置 include后就不需要在这个文件里面配置了 http://www.2cto.com/article/201308/238947.html

	##
	# nginx-passenger config
	##
	# Uncomment it if you installed nginx-passenger
	##
	
	#passenger_root /usr;
	#passenger_ruby /usr/bin/ruby;

	##
	# Virtual Host Configs
	##

	include /etc/nginx/conf.d/*.conf;
	include /etc/nginx/sites-enabled/*;
	# 8000 server yy 文件服务器
	server {
        listen       8000; #指定端口
        server_name  file;#名称
        charset utf-8;#编码
        root   /data/nginxfile ;#根目录
        autoindex on;#自动索引文件
	autoindex_exact_size off;#自动索引大小
	autoindex_localtime on;#展示文件为服务器时间
       }
	# static server 80 静态服务器
       server {
        listen       80;
        server_name  yimaodang.cn;#访问该关键词(网站)时跳转到这个server
        charset utf-8;
        root   /data/staticweb/WebContent;#根目录
        index index.html index.htm;#指定首页
	#这些类型的文件缓存时间是30天
	location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|ico)$
    	{
      expires 30d;
    	}
       }
}


#mail { 邮件服务器,不建议用这个...
#	# See sample authentication script at:
#	# http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
# 
#	# auth_http localhost/auth.php;
#	# pop3_capabilities "TOP" "USER";
#	# imap_capabilities "IMAP4rev1" "UIDPLUS";
# 
#	server {
#		listen     localhost:110;
#		protocol   pop3;
#		proxy      on;
#	}
# 
#	server {
#		listen     localhost:143;
#		protocol   imap;
#		proxy      on;
#	}
#}




求关注,相互交流喔

1. Nginx简介 1.1. 什么是nginx 1.2. Nginx的优点 1.3. 哪里使用到nginx 1.4. Nginx和Apache的区别 2. 安装Nginx服务器 2.1. 在windows上安装 2.2. 在Linux上安装 2.2.1. 写在前面 2.2.2. 准备使用yum安装nginx的运行环境 2.2.3. 安装pcre 2.2.4. 安装zlib库 2.2.5. 安装nginx 2.2.6. 控制nginx 2.2.7. nginx安装服务 3. Nginx配置文件详解 3.1. Nginx的主配置文件概述 3.1.1. 认识配置文件 3.1.2. nginx配置文件结构 3.1.3. nginx的全局配置 3.2. events配置 3.3. http的配置 3.4. nginx重要指令之location 4. nginx中的rewrite 4.1. 什么是rewrite 4.2. rewrite的命令的作用域和优先级 4.3. if指令 4.3.1. if指令的语法 4.3.2. if指令中使用的逻辑运算符 4.3.3. If指令中可以使用的变量 4.3.4. if指令实例 4.4. rewrite指令 4.4.1. rewrite指令语法 4.4.2. flag标记 4.4.3. set指令 4.4.4. return指令 4.4.5. rewrite实例 5. nginx的虚拟主机 5.1. 什么是nginx的虚拟主机 5.2. 标准的虚拟主机配置 5.3. 规划虚拟主机的配置文件 6. 动静分离 7. nginx的反向代理 7.1. 什么是反向代理 7.2. 明确两个概念 7.3. 特点 7.4. 反向代理的配置 7.5. 可以将代理配置单独放在一个配置文件中 8. nginx的负载均衡(自学) 8.1. 什么是负载均衡 8.2. 负载均衡的优点 8.3. 负载均衡的分配策略 8.4. 负载均衡配置 9. 安装PHP 10. PHP-FPM 10.1. 什么是PHP-FPM 10.2. 为什么要是使用PHP-FPM 10.3. 安装并且启动PHP-FPM 10.3.1. 安装 10.3.2. fpm的配置 10.3.3. 启动和停止 10.3.4. 自启动php-fpm 10.3.5. 检查php-fpm是否启动 10.4. nginx使用php-fpm处理php
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值