Front-end architect official group QQ group: 634 196 762
A. Installation node
1. Go to the / usr directory, the new directory toos
cd /usr && mkdir tools && cd tools
2.wget node command to download the corresponding version of the package, download version 8.11.2 here
wget https://npm.taobao.org/mirrors/node/v8.11.2/node-v8.11.2-linux-x64.tar.gz
3. Extract node package, and then change the directory named nodejs
tar xvf node-v10.13.0-linux-x64.tar.xz
// decompression
mv node-v10.13.0-linux-x64 nodejs
// rename
tar -zxf node-v8.11.2-linux-x64.tar.gz
mv node-v8.11.2-linux-x64 nodejs
4. configuration environment variable, so that the command can be used globally node
Into the etc directory, edit the profile file
cd /etc && vim profile
Finally, add the following code in the file:
export NODE_HOME=/usr/tools/nodejs
export PATH=$NODE_HOME/bin:$PATH
export NODE_PATH=$NODE_HOME/lib/node_modules:$PATH
Back / directory, execute
source /etc/profile
Use the reboot command to restart to take effect
Refresh configuration command. Run the node -v in any directory, display the current configuration node version that is installed successfully.
Second, install nginx
1. Installation of dependencies
yum install gcc-c++
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel
2. Use the wget command to download (Recommended)
wget -c https://nginx.org/download/nginx-1.10.1.tar.gz
or
wget -c https://nginx.org/download/nginx-1.16.0.tar.gz
3. Extract the package nginx
/ _ Here _ Do not attempt to change the name /
tar -zxvf nginx-1.10.1.tar.gz
cd nginx-1.10.1
4. default configuration
./configure
5. compile and install
make && make install
6. Find the installation path
whereis nginx
7. Configure global variables
ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx
Commonly used commands:
启动
nginx
重新加载配置
nginx -s reload
重新启动
nginx -s restart
https configuration:
This line can edit this file by executing the command vim /usr/local/nginx/conf/nginx.conf.
Since the version of the problem, the configuration file may be different wording. For example: l using isten 443 ssl
in place and listen 443 ssl on.
Add the page JS script.
Add redirect back-end program.
Jump achieved through the Web server.
Nginx rewrite support functions. If you do not remove pcre at compile time, you can increase the HTTP server in the rewrite ^ https (*.): // $ host $ 1 permanent ;, you can change the default port 80 request redirection to HTTPS. Modify the following:
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;
}
Front-end architect official group QQ group: 634 196 762
Learn the following configuration:
Tencent cloud application ssl https://console.cloud.tencent.com/ssl/detail/YHU6LMvv
nginx configuration
1. Install dependencies
// four mounted thereon a key dependent
yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
2. Download and extract the installation package
// Create a folder
cd / usr / local
mkdir nginx
cd nginx
// download the tar package
wget http://nginx.org/download/nginx-1.13.7.tar.gz
tar -xvf nginx-1.13.7.tar .gz
// enter nginx directory
cd / usr / local / nginx
// execute command
./configure
// make command
make
// execute the command make install
make install
3. Configure nginx.conf
// Open the configuration file
we /usr/local/nginx/conf/nginx.conf
4. Start nginx
/usr/local/nginx/sbin/nginx -s reload
// Check nginx process is started:
PS -ef | grep nginx
If you want to use an external host connection on a virtual machine access port 192.168.131.2, need to shut down the virtual machine firewall:
centOS6 and previous versions use the command: systemctl stop iptables.service
centOS7 turn off the firewall command: systemctl stop firewalld.service
then access the ip to see nginx interface.
Installation commonly used commands
Enter the installation directory,
命令: cd /usr/local/nginx/sbin
Startup, shutdown, restart, the command:
./nginx start
./nginx -s stop closed
./nginx -s reload restart
nginx default configuration default config
#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 file structure
... #全局块
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
}
}
}