nginx源码安装与使用
[root@localhost ~]# yum -y install pcre-devel zlib-devel openssl openssl-devel gcc*
[root@localhost ~]# useradd -r -s /sbin/nologin nginx
[root@localhost nginx-1.12.2]# cd nginx-1.12.2
[root@localhost nginx-1.12.2]# ./configure --prefix=/usr/local/nginx --conf-path=/etc/nginx/nginx.conf --user=nginx --group=nginx --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx/nginx.lock --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module --with-http_flv_module --with-http_mp4_module --http-client-body-temp-path=/var/tmp/nginx/client --http-proxy-temp-path=/var/tmp/nginx/proxy --http-fastcgi-temp-path=/var/tmp/nginx/fastcgi --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi
[root@localhost nginx-1.12.2]# make && make install
[root@localhost nginx-1.12.2]# mkdir -pv /var/tmp/nginx/{client,fastcgi,proxy,uwsgi}
mkdir: 已创建目录 "/var/tmp/nginx"
mkdir: 已创建目录 "/var/tmp/nginx/client"
mkdir: 已创建目录 "/var/tmp/nginx/fastcgi"
mkdir: 已创建目录 "/var/tmp/nginx/proxy"
mkdir: 已创建目录 "/var/tmp/nginx/uwsgi"
[root@localhost nginx-1.12.2]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
[root@localhost nginx-1.12.2]# nginx
[root@localhost ~]# ss -tnl |grep 80
LISTEN     0      128          *:80                       *:*
nginx配置。
[root@localhost ~]# cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak
[root@localhost ~]# vi /etc/nginx/nginx.conf
server {
                listen 8080;
                server_name www.ljj.com;
        }
location / {
            root /webserver/;
            index  index.html index.htm;
        }
[root@localhost ~]# mkdir /webserver
[root@localhost ~]# nginx -s reload
windows端访问:www.ljj.com
nginx基于basic认证的配置
[root@localhost data]# vi /etc/nginx/nginx.conf
server {
                listen 80;
                server_name 192.168.1.222;
        location /data/
        {
                root /locationtest1/;
                index  index.html index.htm;
                auth_basic "welcome to";
                auth_basic_user_file /locationtest1/data/.htpasswd;
        }
        }
[root@localhost ~]# cd /locationtest1/data/
[root@localhost data]# ls
index.html
[root@localhost data]# cat index.html 
192.168.1.334
[root@localhost data]# htpasswd -c -d /locationtest1/data/.htpasswd lishi
New password: 
Re-type new password:       #密码123
Adding password for user lishi
[root@localhost data]# nginx -s reload
windows端访问:192.168.1.222/data/
nginx地址重写
[root@localhost data]# vi /etc/nginx/nginx.conf
server {
                listen 80;
                server_name www.ljj.com;
        location /data/
        {
root /locationtest1/;
                rewrite ^(.*) http://www1.ljj.com$1 last;
                index  index.html index.htm;
        }
        }
        server {
                listen 80;
                server_name www1.ljj.com;
        location /data/
        {
                root /locationtest1/;
                index index.html index.htm;
        }
        }
windows端测试:www.ljj.com/data/会跳转至www1.ljj.com/data/
路径别名
[root@localhost www]# vi /etc/nginx/nginx.conf
server {
                listen 80;
                server_name bbs.ljj.com;
                root /wb1/data;
        location /www/
{
                alias  /ljj/;
                index index.html index.htm;
        }
        }
[root@localhost data]# mkdir -p /wb1/data/www
[root@localhost data]# cd /wb1/data/www/
[root@localhost www]# vi index.html
[root@localhost data]# ls
ljj  www
[root@localhost data]# pwd
/wb1/data
[root@localhost data]# ls www/ ljj/
ljj/:
index.html
www/:
index.html
我正常的主页目录是在/wb1/data/www下,如果有没有路径别名,请求http://www1.ljj.com/www/,响应的就是/wb1/data/www/下的主页。
	如果有路径别名请求http://www1.ljj.com/www/,那就是/ljj/下的主页,
Nginx虚拟目录alias和root目录
nginx是通过alias设置虚拟目录,在nginx的配置中,alias目录和root目录是有区别的:
1)alias指定的目录是准确的,即location匹配访问的path目录下的文件直接是在alias目录下查找的;
2)root指定的目录是location匹配访问的path目录的上一级目录,这个path目录一定要是真实存在root指定目录下的;
3)使用alias标签的目录块中不能使用rewrite的break(具体原因不明);另外,alias指定的目录后面必须要加上"/"符号!!
4)alias虚拟目录配置中,location匹配的path目录如果后面不带"/",那么访问的url地址中这个path目录后面加不加"/"不影响访问,访问时它会自动加上"/";
    但是如果location匹配的path目录后面加上"/",那么访问的url地址中这个path目录必须要加上"/",访问时它不会自动加上"/"。如果不加上"/",访问就会失败!
5)root目录配置中,location匹配的path目录后面带不带"/",都不会影响访问。
调整用户浏览的url
[root@localhost nginx]# vi nginx.conf
server {
listen 80;
server_name www.ljj.com;
location /data/
{
root /locationtest1/;
index index.html index.htm;
}
}
server {
                listen 80;
                server_name ljj.com;
                rewrite ^/(.*) http://www.ljj.com/$1 permanent;
        }
        server {
                listen 80;
        location / {
                root /locationtest1/data/;
                index index.html index.htm;
        }
        }
windows端访问:ljj.com/data/会跳转至www.ljj.com/data/
Nginx域名镜像
server {
                listen 80;
                server_name www.ljj.com;
                root /locationtest1;
        location ^~ /data
        {
rewrite ^/data(.*) http://home.ljj.com/data1$1 last;
                index  index.html index.htm;
        }
        }
server {
                listen 80;
                server_name home.ljj.com;
        location /data1
        {
                root /ngx;
                index index.html index.htm;
        }
        }
        server {
                listen 80;
                server_name www1.ljj.com;
                root /wb1/data;
        location /www/
{
                rewrite ^/www(.*) http://home.ljj.com/data1$1 last;
                index index.html index.htm;
        }
        }
win端访问:www.ljj.com/data跳转至http://home.ljj.com/data1/
win端访问:www1.ljj.com/www跳转至http://home.ljj.com/data1/
目录自动添加/
[root@localhost ~]# mkdir -p /web5/data/
[root@localhost ~]# cd /web5/data/
[root@localhost data]# vi index.html
/web5/data/
[root@localhost nginx]# vi nginx.conf
server {
                listen 80;
                server_name web.ljj.com;
                root /web5;
        location ^~ /data
        {
        if (-d $request_filename)
        {
                rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;
        }
        }
        }
win端访问:web.ljj.com/data/
目录合并
[root@localhost nginx]# vi nginx.conf
server
        {
                listen 80;
                server_name sina.ljj.com;
                root /sina;
        location ^~ /shohu
        {
                rewrite ^/shohu-([0-9]+)-([0-9]+)-([0-9]+)-([0-9]+)-([0-9]+)-([0-9]+)\.html$ /shohu/$1/$2/$3/$4/$5/$6.html last;
        }
        }
[root@localhost ~]# mkdir /sina/shohu/12/23/34/45/56/67/ -p
[root@localhost ~]# cd /sina/shohu/12/23/34/45/56/67/
[root@localhost 67]# vi /sina/shohu/12/23/34/45/56/9.html
/sina/shohu/12/23/34/45/56

防盗链
server {
                listen 80;
                server_name baidu.ljj.com;
                root /locationtest1;
        location ~* ^.+\.(gip|jpg|png|swf|flv|rar|zip)$			#设置防盗链文件类型,自行修改,每个后缀用“|”符号分开!
        {
             valid_referers none blocked server_name *.ljj.com;		#白名单,允许文件链出的域名白名单,自行修改成您的域名!*.ljj.com这个指的是子域名,域名与域名之间使用空格隔开!
             if ($invalid_referer)
             {
                        rewrite ^/ http://baidu.ljj.com/data/forbidden.png;		#这个图片是盗链返回的图片,也就是替换盗链网站所有盗链的图片。这个图片要放在没有设置防盗链的网站上,因为防盗链的作用,这个图片如果也放在防盗链网站上就会被当作防盗链显示不出来了,盗链者的网站所盗链图片会显示X符号。
              }
        }
        }
server {
                listen 80;
                server_name baidu.ljj.com;
                root /locationtest1;
        location /data/
        {
             valid_referers none blocked server_name *.ljj.com;
             if ($invalid_referer)
             {
                        rewrite ^/ http://baidu.ljj.com/data/forbidden.png;
              }
        }
        }
基于浏览器实现分离的。
if($http_user_agent ~ Firefox)
		rewrite ^(.*)$ /firefox/$1 break;
nginx源码安装与使用的更多相关文章
- Nginx源码安装及调优配置
		导读 由于Nginx本身的一些优点,轻量,开源,易用,越来越多的公司使用nginx作为自己公司的web应用服务器,本文详细介绍nginx源码安装的同时并对nginx进行优化配置. Nginx编译前的优 ... 
- Nginx源码安装及调优配置(转)
		导读 由于Nginx本身的一些优点,轻量,开源,易用,越来越多的公司使用nginx作为自己公司的web应用服务器,本文详细介绍nginx源码安装的同时并对nginx进行优化配置. Nginx编译前 ... 
- nginx源码安装方法
		nginx源码安装方法 安装方法如下 1.安装nginx必要的源码依赖软件包. yum -y install gcc gcc-c++ automake pcre pcre-devel zlib zli ... 
- nginx源码安装
		1,首先解决系统环境: 安装rpm包组{CentOS6 跟开发相关的包组:} a. Development Tools #yum groupinstall "Development Too ... 
- nginx 源码安装的重启命令
		源码安装nginx就面临这样的麻烦,不能使用service nginx restart 来重启nginx,没办法只能重新加载下nginx. #/usr/local/nginx/sbin/nginx - ... 
- nginx源码安装教程(CentOS)
		1.说明 官方源码安装说明:http://nginx.org/en/docs/configure.html 源码包下载地址:http://nginx.org/en/download.html 版本说明 ... 
- nginx 源码安装以及后续升级https
		事情的来源是,公司要将网站从http升级到https,由于历史遗留原因,才发现现有的nginx是通过源码安装的,并没有安装ssl模块,需要现安装sll模块,这个nginx是整个公司最前端的一个代理,涉 ... 
- Nginx源码安装配置
		Nginx web服务器简介 Nginx ("engine x") 是一个高性能HTTP 和 反向代理 服务器.IMAP.POP3.SMTP 服务器. Nginx 是由 Igor ... 
- nginx 源码安装配置详解(./configure)
		在"./configure"配置中,"--with"表示启用模块,也就是说这些模块在编译时不会自动构建,"--without"表示禁用模块, ... 
- Nginx 源码安装和调优
		常见web架构: LAMP =Linux+Apache+Mysql+PHP LNMP =Linux+Nginx+Mysql+PHP nginx概述: 知道:1 不知道:2 Nginx (&q ... 
随机推荐
- vmvare虚拟机篇
			新建虚拟机-典型-稍后安装-Linux-管理-从磁盘删除-虚拟机名称-位置- 安装Tools-用于虚拟机和本地文件共享和传送 网络适配器桥接模式-桥接本地网卡 NAT模式-再重新连接本地网卡 仅主机模 ... 
- php 学习笔记之关于时区的那点事
			科普一下什么是时区 众所周知,地球绕着太阳转的同时也会自转,因此同一时刻不同地区所接收到太阳照射的情况不同,所以有的地区是日出,有的地区是日落,还有的地区可能是黑夜. 既然地球上的不同地区时间不同,那 ... 
- Java连载36-IDE使用
			一.主方法注意 每一个类都可以编写一个主方法,但是一般情况下,一个系统只有一个入口,所以主方法一般写一个 二.Myeclipse的使用 1.在workspace中工作区中有一个文件夹.metadata ... 
- touch.js - 移动设备上的手势识别与事件库
			Touch.js 是移动设备上的手势识别与事件库, 由百度云Clouda团队维护,也是在百度内部广泛使用的开发工具.Touch.js手势库专为移动设备设计.Touch.js对于网页设计师来说,是一款不 ... 
- Visual Studio 2019 (VS2019)正式版安装 VisualSVN Server 插件
			VS2019 正式版最近刚刚推出来,目前 Ankhsvn 还不支持,它最高只支持 VS2017,全网搜索了一下,也没有找到.在 Stackoverflow 上看了一下,找到这篇问答: 自己按照这种方法 ... 
- 解决 IDEA 无法找到 java.util.Date 的问题
			原文首发于 studyidea.cn点击查看更多技巧 问题 最近在项目中频繁使用到 java.util.Date,但是使用 IDEA 提示查找 Date 类,却无法找到 java.util.Date. ... 
- Java使用路径通配符加载Resource与profiles配置使用
			序言 Spring提供了一种强大的Ant模式通配符匹配,能从一个路径匹配一批资源. Ant路径通配符 Ant路径通配符支持“?”.“*”.“**”,注意通配符匹配不包括目录分隔符“/”: “?”:匹配 ... 
- CSS 控制文字两端对齐
			<html> <head> <style> td:after { content: ''; } td p{ font-size: 14px; width: 5em; ... 
- 关于 L3 缓存行 cacheLIne 的研究!还是对程序有举足轻重的作用!
			https://www.cnblogs.com/PurpleTide/archive/2010/11/25/1887506.html CLR via C# 读书笔记 2-3 Cache Lines a ... 
- 简单的python GUI例子
			写一个简单的界面很容易,即使是什么都不了解的情况下,这个文本转载了最简单的界面编写,下个文本介绍了TK的简单但具体的应用 在python中创建一个窗口,然后显示出来. from Tkinter imp ... 
