linux环境下载nginx及初步应用

2018-11-24  本文已影响0人  清风徐来_简

一、下载

HTTP/1.1 200 OK
Server: nginx/1.12.0
Date: Wed, 14 Nov 2018 09:57:03 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Wed, 14 Nov 2018 09:42:44 GMT
Connection: keep-alive
ETag: "5bebee14-264"
Accept-Ranges: bytes

如果访问不了,检查selinux,iptables
浏览器访问检测:http://10.0.0.10/ (浏览器不写端口,默认指认80)

├── client_body_temp
├── conf
│   ├── fastcgi.conf
│   ├── fastcgi.conf.default
│   ├── fastcgi_params
│   ├── fastcgi_params.default
│   ├── koi-utf
│   ├── koi-win
│   ├── mime.types
│   ├── mime.types.default
│   ├── nginx.conf
│   ├── nginx.conf.default
│   ├── scgi_params
│   ├── scgi_params.default
│   ├── uwsgi_params
│   ├── uwsgi_params.default
│   └── win-utf
├── fastcgi_temp
├── html
│   ├── 50x.html
│   └── index.html
├── logs
│   ├── access.log
│   ├── error.log
│   └── nginx.pid
├── proxy_temp
├── sbin
│   └── nginx
├── scgi_temp
└── uwsgi_temp

二、基于域名的虚拟主机实战

找到windows的hosts文件,强制一个域名解析
地址:    C:\Windows\System32\drivers\etc\hosts 
(windows8  10的用户,请用管理员运行 )
写入 域名解析
10.0.0.10       www.page1.com
10.0.0.10       www.page2.com
server {
        listen       80;
        server_name  www.page1.com;
        location / {
            root   /opt/static/page1/;
            index  index.html index.htm;
        }
        error_page  404 403 401 402               /404.html;
        error_page   500 502 503 504  /50x.html;(这个x代表数字)
        location = /50x.html {
            root   html;
        }
    }
server  {
        listen  80;
        server_name  www.page2.com;
        location /  {
        root   /opt/static/page2;
        index    index.html;
        }
    }
cd /opt/static/page1 
touch index.html
编辑内容
cd /opt/static/page2 
touch index.html
编辑内容
  • nginx拒绝ip访问:
    如果哪天发现你的nginx很慢,或者检查access.log时候,有一个some body疯狂请求你的nginx server,那么可以禁止这个IP访问
    目录:/opt/nginx1-12/logs/access.log
    检查日志时一直监听:tail -f /opt/nginx1-12/logs/access.log
    限制ip或ip段访问
    location / {
    deny 192.168.1.1;
    deny 192.168.1.0/24;
    allow 10.1.1.0/16;
    }
  • nginx错误页面优化:
    在网站运行过程中,可能因为页面不存在等原因,导致网站无法正常响应请求,此时web服务会返回系统的错误码,但是默认的错误页面很不友好。
    配置参数:
    server {
    listen 80;
    server_name www.yourname.com;
    root html/static;
    location /{
    index index.html index.htm;
    }
    #在static路径下的40x.html错误页面
    error_page 400 403 404 405 /40x.html;
    }
上一篇 下一篇

猜你喜欢

热点阅读