最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Nginx+Windows搭建域名訪問(wèn)環(huán)境的操作方法

 更新時(shí)間:2022年03月17日 10:05:44   作者:隨遇而安==  
這篇文章主要介紹了Nginx搭建域名訪問(wèn)環(huán)境,包括nginx配置文件的相關(guān)介紹及對(duì)nginx配置文件的分析,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

一、修改 Windows hosts 文件

位置:C:\Windows\System32\drivers\etc

在后面追加以下內(nèi)容:

# guli mall #
192.168.163.131		gulimall.com

二、Nginx 配置文件

三、分析Nginx配置文件

cat /mydata/nginx/conf/nginx.conf  
user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;
events {
    worker_connections  1024;
}
http {
    include       /etc/nginx/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  /var/log/nginx/access.log  main;
    sendfile        on;
    #tcp_nopush     on;
    keepalive_timeout  65;
    #gzip  on;
    include /etc/nginx/conf.d/*.conf;

可以看到,在 http 塊中最后有 include /etc/nginx/conf.d/*.conf; 這句配置說(shuō)明在 conf.d 目錄下所有 .conf 后綴的文件內(nèi)容都會(huì)作為 nginx 配置文件 http 塊中的配置。這是為了防止主配置文件太復(fù)雜,也可以對(duì)不同的配置進(jìn)行分類。

下面我們參考 conf.d 目錄下的配置,來(lái)配置 gulimall 的 server 塊配置

四、gulimall.conf

默認(rèn)配置下,我們?cè)L問(wèn) gulimall.com 會(huì)請(qǐng)求 nginx 默認(rèn)的 index 頁(yè)面,現(xiàn)在我們要做的是當(dāng)訪問(wèn) gulimall.com 的時(shí)候轉(zhuǎn)發(fā)到我們的商品模塊的商城首頁(yè)界面。

4.1 查看Windows ip

打開cmd 輸入 ipconfig

這里的 192.168.17.1 和 192.168.163.1 也是 Windows 的本機(jī)地址

所以我們配置當(dāng)訪問(wèn) nginx /請(qǐng)求時(shí)代理到 192.168.163.1:10000 商品服務(wù)首頁(yè)

4.2 配置代理

server {
    listen       80;
    server_name  gulimall.com;

    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;
    location / {
      proxy_pass http://192.168.163.1:10000;
    }
    #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   /usr/share/nginx/html;
}

五、圖示

六、反向代理:nginx 代理網(wǎng)關(guān)由網(wǎng)關(guān)進(jìn)行轉(zhuǎn)發(fā)

6.1 修改 nginx.conf

vim /mydata/nginx/conf/nginx.conf

修改 http 塊,配置上游服務(wù)器為網(wǎng)關(guān)地址

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;
events {
    worker_connections  1024;
}
http {
    include       /etc/nginx/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  /var/log/nginx/access.log  main;
    sendfile        on;
    #tcp_nopush     on;
    keepalive_timeout  65;
    #gzip  on;
    upstream gulimall {
        server 192.168.163.1:88;
    }
    include /etc/nginx/conf.d/*.conf;

6.2 修改 gulimall.conf

配置代理地址為上面配置的上游服務(wù)器名

server {
    listen       80;
    server_name  gulimall.com;

    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;
    location / {
      proxy_set_header Host $host;
      proxy_pass http://gulimall;
    }
    #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   /usr/share/nginx/html;
}

 

七、訪問(wèn)跳轉(zhuǎn)分析

當(dāng)前通過(guò)域名的方式,請(qǐng)求 gulimal.com ;

根據(jù) hosts 文件的配置,請(qǐng)求 gulimall.com 域名時(shí)會(huì)請(qǐng)求虛擬機(jī) ip

192.168.163.131		gulimall.com

當(dāng)請(qǐng)求到 192.168.163.131:80 時(shí),會(huì)被 nginx 轉(zhuǎn)發(fā)到我們配置的 192.168.163.1:10000 路徑,該路徑為運(yùn)行商品服務(wù)的 windows 主機(jī) ip 地址,至此達(dá)到通過(guò)域名訪問(wèn)商品服務(wù)的目的。

server {
    listen       80;
    server_name  gulimall.com;
    location / {
      proxy_pass http://192.168.163.1:10000;
    }
}

7.1 后面的跳轉(zhuǎn)分析

之后為了統(tǒng)一管理我們的各種服務(wù),我們將通過(guò)配置網(wǎng)關(guān)作為 nginx 轉(zhuǎn)發(fā)的目標(biāo)。最后通過(guò)配置網(wǎng)關(guān)根據(jù)不同的域名來(lái)判斷跳轉(zhuǎn)對(duì)應(yīng)的服務(wù)。

到此這篇關(guān)于Nginx搭建域名訪問(wèn)環(huán)境的文章就介紹到這了,更多相關(guān)Nginx搭建域名訪問(wèn)環(huán)境內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論

林芝县| 拜泉县| 井冈山市| 青神县| 调兵山市| 固阳县| 湖南省| 呼图壁县| 高陵县| 玉树县| 永泰县| 赫章县| 新干县| 吉林市| 墨江| 柏乡县| 文成县| 胶南市| 丹棱县| 靖安县| 仙游县| 凉城县| 安徽省| 鄂伦春自治旗| 威宁| 洛南县| 南安市| 改则县| 淮南市| 电白县| 溆浦县| 桐城市| 遵义市| 抚顺县| 视频| 大邑县| 巩义市| 柳林县| 望谟县| 永靖县| 宁津县|