nginx 와 apache 가 함께 도망 가기 - 역방향 대리

4752 단어
nginx 와 apache 가 함께 역방향 대 리 를 하면 각자 의 장점 은 자세히 말 하지 않 습 니 다. 어차피 하나의 처리 병발 과 정태 적 인 소 차 이 는 동태 적 인 소 차 이 를 처리 합 니 다.
apache 가 설 치 를 어떻게 실행 하 는 지 보고 싶 으 면 제 다른 centos 7 LAMP 설치 와 주의사항 을 볼 수 있 습 니 다.
1. apache 관련 프로필 변경 포트 번호
주 프로필:
vi /etc/httpd/conf/httpd.conf
Listen 81

가상 호스트 설정 파일:
vi /etc/httpd/conf.d/lock.com.conf

<VirtualHost 192.168.136.128:81>
    DirectoryIndex index.php
    ServerAdmin [email protected]
    DocumentRoot /www/lockcom
    ServerName lock.com
    ServerAlias lock.com

        <Directory /www/lockcom>
                Options Indexes FollowSymLinks
                AllowOverride None
                Require all granted
        </Directory>

</VirtualHost>

브 라 우 저 열기
http://lock.com:81
방문 할 수 있 을 겁 니 다.
2. nginx 설치
yum 으로 설치 해 주세요.
yum nginx install
/bin/systemctl start  nginx.service
systemctl status nginx.service

브 라 우 저 열기
http://lock.com
nginx 환영 페이지
3. nginx 관련 프로필 변경
nginx. conf 주 프로필:
주로 proxypass 역방향 대리
apache 가상 호스트 에 고정 IP 주 소 를 사용 했다 면 proxypass 는 같은 IP 주소 일 것 입 니 다. 설정 되 어 있 지 않 으 면 127.0.0.1 을 정상적으로 사용 하면 됩 니 다.
nginx 의 가상 호스트 설정 디 렉 터 리 를 만 들 고 홈 설정 파일 에 include / etc / nginx / vhost / *. conf 를 포함 합 니 다.
mkdir /etc/nginx/vhost
touch /etc/nginx/vhost/lock.com.conf

다음 nginx 메 인 프로필:
nginx.conf
# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    server {
        #listen       80 default_server;
        #listen       [::]:80 default_server;
        listen       80;
        server_name  _;
        #root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        # include /etc/nginx/default.d/*.conf;

       
        location / {
                try_files $uri @apache;
                }


        location @apache {
                internal;
                proxy_pass http://192.168.136.128:81;
                }

        location ~ .*\.(php|php5)?$  {
                proxy_pass http://192.168.136.128:81;
                }

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ {
                expires 30d;
                }

        location ~ .*\.(js|css)?$ {
                expires 7d;
                }


        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }
    include /etc/nginx/vhost/*.conf;
}

가상 호스트 의 설정 vhost / lock. com. conf
vi /etc/nginx/vhost/lock.com.conf
server {
listen 80;
server_name lock.com;
access_log /www/wwwlogs/lock.com_nginx.log combined;
index index.html index.htm index.jsp index.php;
root /www/lockcom;
#error_page 404 /404.html;
if ( $query_string ~* ".*[\;'\<\>].*" ){
        return 404;
        }
if ( $http_user_agent ~ ApacheBench|WebBench|Jmeter|must-revalidate|Havij ){
        return 503;
        }


location ~ .*\.(wma|wmv|asf|mp3|mmf|zip|rar|jpg|gif|png|swf|flv)$ {
        valid_referers none blocked nahehuo.com *.nahehuo.com;
        if ($invalid_referer) {
                #rewrite ^/ http://www.lock.com/403.html;
                return 403;
                }
        }
limit_rate 500k;
location / {
        try_files $uri @apache;
        }

location @apache {
        internal;
        proxy_pass http://192.168.136.128:81;
        }

location ~ .*\.(php|php5)?$ {
        proxy_pass http://192.168.136.128:81;
        }
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ {
        expires 30d;
        }

location ~ .*\.(js|css)?$ {
        expires 7d;
}

}

좋은 웹페이지 즐겨찾기