一 nginx的概念和作用
1.1 概念
1.nginx是一個代理靜態資源的高性能http服務器和反向代理的服務器,
1.2 作用
1.代理靜態資源:可以做靜態網頁的http服務器,
2.反向代理、負載均衡,:把請求轉發給不同的服務器
3.解決跨域
4.配置虛擬機,
一個域名可以被多個ip系結,可以根據域名的不同吧請求轉發給運行在不同埠的服務器
1.3 啟動關閉
1.啟動: 在nginx目錄下有一個sbin目錄,sbin目錄下有一個nginx可執行程式: ./nginx
2.查看nginx的行程

3.關閉
關閉命令:相當于找到nginx行程kill,
./nginx -s stop
退出命令:
./nginx -s quit
等程式執行完畢后關閉,建議使用此命令,
4.重新加載
./nginx -s reload
可以不關閉nginx的情況下更新組態檔,
二 靜態資源代理
2.1 nginx的配置
1.config的配置

2.存放的實際資源

3.訪問頁面

三 虛擬主機
3.1 同一臺nginx虛擬兩臺服務器
nginx的組態檔:
1.第一個server塊

2.第二個server塊:
3.資源位置:

訪問80:

訪問8081:

四 同一臺nginx代理多個不同的靜態資源
80埠 下 存盤 vue的靜態頁面: html/dky-guolu-vue
新建一個server塊,埠為8099,創建一個存盤react靜態頁面: html/dky-guolu-react/;
#前端react頁面
server {
listen 8099;
server_name localhost;
location / {
root html/dky-guolu-react/;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
并且將react代理到80埠下,配置如下配置 :
#前端react的頁面
location /react {
proxy_pass http://32.32.255.239:8099/;
#root html;
#index index.html index.htm;
}
訪問地址:http://32.32.255.239:80/react/index.html
原先地址:http://32.32.255.239:8099/index.html
#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;
#懸掛vue選單頁面
location / {
#proxy_pass http://172.16.71.134:8080;
root html/dky-guolu-vue;
index index.html index.htm;
}
#門戶前端
location /frame/ {
proxy_pass http://32.32.255.239:8989/frame/;
#root html;
#index index.html index.htm;
}
#調取cloudiip
location /cloudiip-cas {
proxy_pass http://32.32.255.241:80/;
#root html;
#index index.html index.htm;
}
#代理綜合爆炸圖-一次風機
location /zhbz-3ycfj {
proxy_pass http://32.32.255.239:8098/;
#root html;
#index index.html index.htm;
}
#代理綜合爆炸圖-送風機
location /zhbz-3sfj {
proxy_pass http://32.32.255.239:8096/;
#root html;
#index index.html index.htm;
}
#代理綜合爆炸圖-一次風機
location /zhbz-3yfj {
proxy_pass http://32.32.255.239:8095/;
#root html;
#index index.html index.htm;
}
#前端react的頁面
location /react {
proxy_pass http://32.32.255.239:8099/;
#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;
#}
}
#綜合-爆炸圖-一次風機
server {
listen 8098;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html/dky-guolu-vue/webgl/3ycfj;
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;
#}
}
#綜合-爆炸圖-送風機
server {
listen 8096;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html/dky-guolu-vue/webgl/3sfj;
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;
#}
}
#綜合-爆炸圖-引風機
server {
listen 8095;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html/dky-guolu-vue/webgl/3yfj;
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;
#}
}
#綜合脫硫圖
server {
listen 8097;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html/dky-guolu-vue/webgl/webGL2;
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;
#}
}
#前端react頁面
server {
listen 8099;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html/dky-guolu-react/;
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;
# }
#}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/347242.html
標籤:其他
