Nginx+rewrite+proxy+cache Basic Experiment

Source: Internet
Author: User
Tags fully qualified domain name

Share the next Nginx+rewrite+proxy+cache today
The difference between Nginx and Apache

1.nginx based on IP restrictions
Small experiment:

worker_processes  1;events {    worker_connections  1024;}http {    include       mime.types;    default_type  application/octet-stream;    sendfile        on;    keepalive_timeout  65;    server {        listen       80;        server_name  www.abc.com;          location / {            root   html/abc;            index  index.html index.htm;        }                location ~ \.doc$ {        (访问以doc结尾的文件只允许13这台机器,顺序控制。)                   root   html/abc;                   allow 192.168.10.13;                   deny  all;                }    }}


  * * Based on user Password control **[[email protected] conf]# yum install-y httpd-tools[[email protected] conf]# Htpasswd-cm/usr/local/nginx/passwd.db bokenew password:re-type new password:adding password for user boke[[email  Protected] conf]# Cat/usr/local/nginx/passwd.dbboke: $apr 1$psoqfioj$2llfh0gedt5feekx5wbfd.        [[email protected] conf]# vim nginx.conf server_name www.abc.com;            Location/{Auth_basic "Please enter user name and password";                        Auth_basic_user_file "/usr/local/nginx/passwd.db"; [[email protected] conf]# restartnx (This is an alias) alias Restartnx= '/usr/local/nginx/sbin/nginx -S reload ' [Nginx log rotation] (http://blog.51cto.com/lookingdream/1794169)  
  Rewrite experiment [[email protected] conf]# vim nginx.confserver {Listen 80;        server_name www.joy.com;            Location/{charset utf-8;            Root Html/joy;        Index index.html index.htm;    Location ~/boke/.* {rewrite ^/boke/.*/boke/index.html break; [[email protected] conf]# tree/usr/local/nginx/html/joy//usr/local/nginx/html/joy/├──boke│?? ├──1.html│?? ├──2.html│?? └──index.html└──index.html  
# proxy reverse proxy [[email protected] conf]# vim nginx.confserver {Listen 80;        server_name www.joy.com; Location/{Proxy_pass http://192.168.10.15; (Access www.joy.com to the back-end server's IP, but does this pose a problem?) How can I access multiple URLs? }}} using Nginx's own variables.        server {Listen 80;        server_name www.joy.com; Location/{proxy_pass Http://192.168.10.15;proxy_set_header Host $host;p roxy_set_header x-real-ip $remote          _ADDR, #proxy_set_header x-forwarded-for $remote _addr;proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;        }}server {Listen 80;        server_name www.sss.com;                Location/{Proxy_pass http://192.168.10.15; Proxy_set_header Host $host;p roxy_set_header x-real-ip $remote _addr; #proxy_set_header x-forwarded-for $remote _addr;          Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for; }}192.168.10.15web Server Configuration Two virtual host starting Httpd:httpd:apR_sockaddr_info_get () failed for dns-masterhttpd:could not reliably determine the server ' s fully qualified domain name, u Sing 127.0.0.1 for servername[wed-02:30:26 2018] [warn] _default_ VirtualHost overlap on port, the first have pre Cedence [OK] (start times wrong, one parameter of httpd.conf not open, uncomment can) [[EMAIL PR                                                                                                                       Otected] conf]# vim httpd.conf    # use name-based virtual hosting.                                                                                                                  #NameVirtualHost *:80
轮训策略默认为1:1侧重轮训   绑定轮训  这里使用默认轮训upstream apache_pool {server 192.168.10.15;server 192.168.10.14;}server {        listen       80;        server_name  www.joy.com;        location / {                proxy_pass http://apache_pool;  (这里写的是地址池)proxy_set_header Host $host;


Nginx Cache

nginx可以使用缓存,减轻后端服务器压力[[email protected] nginx]# vim nginx.conf  (主配置文件)

虚拟主机配置

Next time Share Lnmp.

Nginx+rewrite+proxy+cache Basic Experiment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.