Nginx의 프런트 엔드 학습

프런트 엔드 건축가 공식 그룹 QQ 그룹 : 634 196 762

A. 설치 노드

는 / usr 디렉토리로 이동, 새 디렉토리 했답니다

cd /usr && mkdir tools && cd tools

패키지의 해당 버전을 다운로드 할 수 2.wget 노드 명령, 여기 다운로드 버전 8.11.2

wget https://npm.taobao.org/mirrors/node/v8.11.2/node-v8.11.2-linux-x64.tar.gz

3. 추출 노드 패키지는 다음 디렉토리의 이름 nodejs 변경

tar xvf node-v10.13.0-linux-x64.tar.xz// 압축 해제
mv node-v10.13.0-linux-x64 nodejs// 이름 바꾸기

tar -zxf node-v8.11.2-linux-x64.tar.gz
mv node-v8.11.2-linux-x64 nodejs

4. 구성 환경 변수이므로 명령 노드 전체적으로 사용될 수 있다는

전문 의약품 디렉토리에, 편집 프로필 파일

cd /etc && vim profile

마지막으로, 파일에 다음 코드를 추가합니다 :

export NODE_HOME=/usr/tools/nodejs
export PATH=$NODE_HOME/bin:$PATH
export NODE_PATH=$NODE_HOME/lib/node_modules:$PATH

돌아 가기 / 디렉토리, 실행

source /etc/profile

을 적용하려면 다시 시작하려면 reboot 명령을 사용하여

새로 고침 구성 명령. 어떤 디렉토리에있는 노드 -v를 실행하여 성공적으로 설치되어있는 현재 구성 노드 버전을 표시합니다.

둘째, nginx를 설치

종속성 1. 설치

yum install gcc-c++

yum install -y pcre pcre-devel

yum install -y zlib zlib-devel

yum install -y openssl openssl-devel

2. 다운로드에 wget과 명령 (권장)

wget -c https://nginx.org/download/nginx-1.10.1.tar.gz

또는

wget -c https://nginx.org/download/nginx-1.16.0.tar.gz

패키지의 nginx를 추출합니다

/ _ 다음 _ 이름을 변경하지 마십시오 /

tar -zxvf nginx-1.10.1.tar.gz
cd nginx-1.10.1

4. 기본 구성

./configure

컴파일 및 설치 (5)

make && make install

설치 경로를 찾기 (6)

whereis nginx

7. 구성 전역 변수

ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx

일반적으로 사용되는 명령 :

启动

nginx

重新加载配置

nginx -s reload

重新启动

nginx -s restart

HTTPS 구성 :

이 줄은 명령 정력 /usr/local/nginx/conf/nginx.conf을 실행하여이 파일을 편집 할 수 있습니다.
문제의 버전 때문에, 구성 파일의 서로 다른 표현 될 수있다. 예를 들어 : L 사용 isten 443 ssl장소와 443 SSL을들을 수 있습니다.
페이지 JS 스크립트를 추가합니다.
리디렉션 백엔드 프로그램을 추가합니다.
웹 서버를 통해 달성 이동합니다.
지원 기능을 재 작성 nginx를. 당신이 컴파일시에 PCRE를 제거하지 않으면, 당신은 재 ^ HTTPS에서 HTTP 서버를 늘릴 수 있습니다 (*.) // $ 호스트 $ 1 영구;, 당신은 HTTPS에 대한 기본 포트 80을 요청 재 지정을 변경할 수 있습니다. 다음을 수정합니다 :

server {
listen 443;
#填写绑定证书的域名
server_name www.domain.com; 
ssl on;
#网站主页路径。此路径仅供参考,具体请您按照实际目录操作。
root /var/www/www.domain.com; 
index index.html index.htm;   
#证书文件名称
ssl_certificate  1_www.domain.com_bundle.crt; 
#私钥文件名称
ssl_certificate_key 2_www.domain.com.key; 
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
location / {
   index index.html index.htm;
}
}
server {
listen 80;
#填写绑定证书的域名
server_name www.domain.com; 
#把http的域名请求转成https
rewrite ^(.*)$ https://$host$1 permanent; 
}

프런트 엔드 건축가 공식 그룹 QQ 그룹 : 634 196 762

다음과 같은 구성을 알아보기 :

텐센트 클라우드 애플리케이션 SSL https://console.cloud.tencent.com/ssl/detail/YHU6LMvv

의 nginx 구성

종속성을 설치 (1)

// 네는 키 의존을 탑재
GCC ZLIB ZLIB-(STABLE)의 설치 -y 냠 PCRE-(STABLE)하려면 openssl하려면 openssl-(STABLE)을

2. 다운로드 및 설치 패키지를 추출

// 생성 폴더
CD / usr / 지방
에서 mkdir의 nginx의
CD의 nginx
// 타르 패키지를 다운로드
wget을 http://nginx.org/download/nginx-1.13.7.tar.gz
타르 -xvf의 nginx-1.13.7.tar 에 .gz

// 입력의 nginx 디렉토리
CD / usr / 지방 / nginx를
// 실행 명령
./configure를
// make 명령
메이크업
// 명령 make가 설치 실행
메이크업 설치

3. 구성 nginx.conf

// 구성 파일을 엽니 다

우리는 /usr/local/nginx/conf/nginx.conf

4. 시작의 nginx

/ usr / 지방 / Nginx의 경우 / sbin / nginx를 -s 다시로드

// 확인의 nginx 프로세스가 시작됩니다 :

PS -ef | 그렙의 nginx

가상 컴퓨터 액세스 포트 192.168.131.2의 외부 호스트 연결을 사용하려는 경우, 필요 가상 컴퓨터 방화벽을 종료합니다 :
systemctl 정지 iptables.service : centOS6 및 이전 버전의이 명령을 사용하여

systemctl 정지 firewalld.service : centOS7 방화벽 명령을 해제
한 후 nginx를 인터페이스를 확인하기 위해 IP를 액세스 할 수 있습니다.

설치 일반적으로 사용되는 명령

설치 디렉토리를 입력

命令 : CD / usr / 지방 /의 nginx / sbin에

시작, 종료, 재시작 명령 :

./nginx 시작

./nginx -s 정류장은 폐쇄

./nginx -s 다시로드를 다시 시작

nginx를 기본 구성 기본 설정

 #user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #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  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

Nginx의 파일 구조

...              #全局块

events {         #events块
   ...
}

http      #http块
{
    ...   #http全局块
    server        #server块
    {
        ...       #server全局块
        location [PATTERN]   #location块
        {
            ...
        }
        location [PATTERN]
        {
            ...
        }
    }
    server
    {
      ...
    }
    ...     #http全局块
}

########### 每个指令必须有分号结束。#################
#user administrator administrators;  #配置用户或者组,默认为nobody nobody。
#worker_processes 2;  #允许生成的进程数,默认为1
#pid /nginx/pid/nginx.pid;   #指定nginx进程运行文件存放地址
error_log log/error.log debug;  #制定日志路径,级别。这个设置可以放入全局块,http块,server块,级别以此为:debug|info|notice|warn|error|crit|alert|emerg
events {
    accept_mutex on;   #设置网路连接序列化,防止惊群现象发生,默认为on
    multi_accept on;  #设置一个进程是否同时接受多个网络连接,默认为off
    #use epoll;      #事件驱动模型,select|poll|kqueue|epoll|resig|/dev/poll|eventport
    worker_connections  1024;    #最大连接数,默认为512
}
http {
    include       mime.types;   #文件扩展名与文件类型映射表
    default_type  application/octet-stream; #默认文件类型,默认为text/plain
    #access_log off; #取消服务日志
    log_format myFormat '$remote_addr–$remote_user [$time_local] $request $status $body_bytes_sent $http_referer $http_user_agent $http_x_forwarded_for'; #自定义格式
    access_log log/access.log myFormat;  #combined为日志格式的默认值
    sendfile on;   #允许sendfile方式传输文件,默认为off,可以在http块,server块,location块。
    sendfile_max_chunk 100k;  #每个进程每次调用传输数量不能大于设定的值,默认为0,即不设上限。
    keepalive_timeout 65;  #连接超时时间,默认为75s,可以在http,server,location块。

    upstream mysvr {
      server 127.0.0.1:7878;
      server 192.168.10.121:3333 backup;  #热备
    }
    error_page 404 https://www.baidu.com; #错误页
    server {
        keepalive_requests 120; #单连接请求上限次数。
        listen       4545;   #监听端口
        server_name  127.0.0.1;   #监听地址
        location  ~*^.+$ {       #请求的url过滤,正则匹配,~为区分大小写,~*为不区分大小写。
           #root path;  #根目录
           #index vv.txt;  #设置默认页
           proxy_pass  http://mysvr;  #请求转向mysvr 定义的服务器列表
           deny 127.0.0.1;  #拒绝的ip
           allow 172.18.5.54; #允许的ip
        }
    }
}

프런트 엔드 건축가 공식 그룹 QQ 그룹 : 634 196 762

게시 된 155 개 원래 기사 · 원 찬양 57 ·은 60000 +를 볼

추천

출처blog.csdn.net/weixin_43764814/article/details/102886218