久久久久在线观看_又色又爽又黄的免费视频播放_一区中文字幕_日韩电影在线播放

今日頭條 焦點(diǎn)資訊 營(yíng)銷之道 企業(yè)報(bào)道 淘寶運(yùn)營(yíng) 網(wǎng)站建設(shè) 軟件開發(fā) 400電話
  當(dāng)前位置: 首頁(yè) » 資訊 » 軟件開發(fā) » 正文

Windows下Nginx的安裝及配置實(shí)例講解

放大字體  縮小字體 發(fā)布日期:2018-03-01  來(lái)源:企業(yè)800網(wǎng)  作者:新格網(wǎng)  瀏覽次數(shù):672  【去百度看看】
核心提示:本文主要和大家分享Windows下Nginx的安裝及配置實(shí)例講解,希望能幫助到大家。

本文主要和大家分享Windows下Nginx的安裝及配置實(shí)例講解,希望能幫助到大家。

一、Nginx簡(jiǎn)介

1.Nginx是什么

Nginx是一款輕量級(jí)Web服務(wù)器、也是一款反向代理服務(wù)器

2.Nginx能干什么

①可直接支持Rails和PHP的程序
②可作為HTTP反向代理服務(wù)器
③作為負(fù)載均衡服務(wù)器
④作為郵件代理服務(wù)器
⑤幫助實(shí)現(xiàn)前端動(dòng)靜分離

3.Nginx特點(diǎn)

  • 高穩(wěn)定

  • 高性能

  • 資源占用少

  • 功能豐富

  • 模塊化結(jié)構(gòu)

  • 支持熱部署

二、Nginx安裝

1.下載:http://nginx.org/download/nginx-1.10.2.zip

2.解壓縮

3.運(yùn)行nginx.exe:通過(guò)雙擊圖標(biāo)或者cmd命令行運(yùn)行

三、Nginx常用命令

1.測(cè)試配置文件

安裝路徑下的 nginx.exe -t

2.啟動(dòng)命令

安裝路徑下的 nginx.exe

3.停止命令

安裝路徑下的 nginx.exe -s stop,
或者是:nginx.exe -s quit

4.重啟命令

安裝路徑下的 nginx.exe -s reload

5.查看進(jìn)程命令

ps -ef |grep nginx

6.平滑重啟

kill -HUP 【Nginx主進(jìn)程號(hào)(即查看進(jìn)程命令查到的PID)】

7.增加防火墻訪問(wèn)權(quán)限

①sudo vim /etc/sysconfig/iptables
②-A INPUT -p tcp -m state –state NEW
-m tcp –dport 80 -j ACCEPT
③保存退出
④重啟防火墻 sudo service iptables restart

四、Nginx虛擬域名配置及測(cè)試驗(yàn)證

配置步驟:

1.編輯sudo vim /usr/local/nginx/conf/nginx.conf
①增加include vhost/*.conf;
②保存退出

nginx.conf.jpg

2.在/usr/local/nginx/conf/目錄新建vhost文件夾:
即:/user/local/nginx/conf/vhost

3.創(chuàng)建域名轉(zhuǎn)發(fā)配置文件

image.hcxjingdong.com.conf:轉(zhuǎn)向目錄的反向代理:
server {
    listen 80;
    autoindex off;
    server_name image.hcxjingdong.com;
    access_log c: /access.log combined; index index.html index.htm index.jsp index.php; #error_page 404 /
    404. html;
    if ($query_string~ * ".*[\;'\<\>].*") {
        return 404;
    }
    location~/(mmall_fe|mmall_admin_fe)/dist / view /* { 
        deny all; 
    } 
    location / { 
        root C:\ftpfile\img; 
        add_header Access-Control-Allow-Origin *; 
        } 
    }


tomcat.hcxjingdong.com.conf:轉(zhuǎn)向端口的反向代理:
server {
    listen 80;
    autoindex on;
    server_name tomcat.hcxjingdong.com;
    access_log c: /access.log combined; index index.html index.htm index.jsp index.php; #error_page 404 /
    404. html;
    if ($query_string~ * ".*[\;'\<\>].*") {
        return 404;
    }
    location / {
            proxy_pass http: //127.0.0.1:8080; 
            add_header Access-Control-Allow-Origin *; 
            } 
    }

4.啟動(dòng)(重啟)驗(yàn)證
①啟動(dòng):

{nginx}/sbin/nginx -s reload

注:${nginx}代表安裝在系統(tǒng)中的路徑,例如:/usr/local/nginx

5.訪問(wèn)驗(yàn)證

使用默認(rèn)80端口訪問(wèn)驗(yàn)證:http://localhost:80或http://127.0.0.1:80

6.指向端口

http轉(zhuǎn)發(fā)

server{
    listen 80;
    autoindex off;
    server_name learning.hcxjingdong.com;
    access_log c:/access.log combined;
    index index.html index.htm index.jsp index.php;
    #error_page 404 /404.html;
    if ( $query_string ~* ".*[\;'\<\>].*" ){
        return 404;
    }
    location / {
        proxy_pass http://127.0.0.1:81/learning;
        add_header Access-Control-Allow-Origin *;
    }
}

listen 80:監(jiān)聽80端口;
autoindex off:是否創(chuàng)建首頁(yè)的索引目錄;
當(dāng)nginx接到image.hcxjingdong.com(二級(jí)域名)請(qǐng)求,就轉(zhuǎn)發(fā)到:http://127.0.0.1:81/learning目錄下

7.指向目錄

線上圖片服務(wù)器,為前端提供的前端部署服務(wù)器都是通過(guò)指向目錄的反向代理

server{
    listen 80;
    autoindex off;
    server_name img.hcxjingdong.com;
    access_log c:/access.log combined;
    index index.html index.htm index.jsp index.php;
    #root /product/front/;
    #error_page 404 /404.html;
    if ( $query_string ~* ".*[\;'\<\>].*" ){
        return 404;
    }
    location ~ /(hcxjingdong_fe|hcxmall_admin_fe)/dist/view/* {
        deny all;
    }
    location / {
        root \product\ftpfile\img;
        add_header Access-Control-Allow-Origin *;
    }
}

root /product/ftpfile/img:
root直接指向硬盤系統(tǒng)目錄product文件夾下的ftpfile下的img文件夾;
即在訪問(wèn)img.hcxjingdong.com的時(shí)候就直接指向了該文件夾

8.測(cè)試驗(yàn)證

驗(yàn)證成功頁(yè)面.jpg

五、Nginx注意事項(xiàng)

可以配置域名轉(zhuǎn)發(fā),但請(qǐng)一定要配置host,并且使host生效之后才可以,設(shè)置完成之后要重啟瀏覽器

Windows下配置:
①進(jìn)入c:\Windows\System32\drivers\etc
②用記事本打開hosts文件
③添加好對(duì)應(yīng)的域名及ip
④保存退出

例如:
10.211.55.6 image.hcx.com
10.211.55.6 s.hcx.com

添加域名及ip.jpg

六、配置Windows下的Nginx

配置hosts:
c:\Windows\System32\drivers\etc

配置hosts.jpg

用瀏覽器訪問(wèn)www.hcxjingdong.com

驗(yàn)證hosts配置.jpg

包括本機(jī)訪問(wèn)http://localhost:

本機(jī)訪問(wèn).jpg

配置目錄的轉(zhuǎn)發(fā)

1.進(jìn)入到nginx.conf(nginx的主配置):
添加:include vhost/*.conf;

修改nginx.conf.jpg

2.按照該路徑去創(chuàng)建此文件夾:
在conf文件夾下創(chuàng)建vhost文件夾

創(chuàng)建vhost文件夾.jpg

3.在vhost文件夾中創(chuàng)建文件:image.hcxjingdong.com.conf

創(chuàng)建image.hcxjingdong.com.conf.jpg

文件內(nèi)容:

server{
    listen 80;
    autoindex off;
    server_name image.hcxjingdong.com;
    access_log c:/access.log combined;
    index index.html index.htm index.jsp index.php;
    #error_page 404 /404.html;
    if ( $query_string ~* ".*[\;'\<\>].*" ){
        return 404;
    }

    location ~ /(hcxmall_fe|hcxmall_admin_fe)/dist/view/* {
        deny all;
    }

    location / {
        root C:\ftpfile\img;
        add_header Access-Control-Allow-Origin *;
    }
}

到C:\ftpfile\img目錄下存放圖片以便訪問(wèn)

4.修改本機(jī)的host,讓本機(jī)的nginx配合到image.hcxjingdong.com域名

去到C:\Windows\System32\drivers\etc目錄下修改hosts文件:

修改本機(jī)的host.jpg

5.重啟nginx:

進(jìn)入到nginx目錄執(zhí)行命令:
①nginx.exe -t:驗(yàn)證配置文件是否正確
②nginx.exe -s reload:重啟nginx

驗(yàn)證并重啟nginx.jpg

6.訪問(wèn)域名(image.hcxjingdong.com)驗(yàn)證圖片是否生效:

測(cè)試host是否生效:image.hcxjingdong.com
測(cè)試圖片是否生效:http://image.hcxjingdong.com/hcx.jpg

驗(yàn)證是否生效.jpg

配置ip端口的轉(zhuǎn)發(fā)

1.在conf下的vhost下創(chuàng)建:tomcat.hcxjingdong.com.conf

創(chuàng)建tomcat.hcxjingdong.com.conf.jpg

使用tomcat域名進(jìn)行ip端口轉(zhuǎn)發(fā),轉(zhuǎn)發(fā)到tomcat服務(wù)上

tomcat.hcxjingdong.com.conf:

server{
    listen 80;
    autoindex off;
    server_name tomcat.hcxjingdong.com;
    access_log c:/access.log combined;
    index index.html index.htm index.jsp index.php;
    #error_page 404 /404.html;
    if ( $query_string ~* ".*[\;'\<\>].*" ){
        return 404;
    }
    location / {
        proxy_pass http://127.0.0.1:8080;
        add_header Access-Control-Allow-Origin *;
    }
}

2.配置hosts:

配置hosts2.jpg

3.啟動(dòng)tomcat

4.重啟nginx:nginx.exe -s reload

5.訪問(wèn)http://tomcat.hcxjingdong.com
成功顯示tomcat啟動(dòng)頁(yè),說(shuō)明http的轉(zhuǎn)發(fā)也成功了。

相關(guān)推薦:

Windows下Nginx的安裝與配置

nginx的安裝配置

Nginx學(xué)習(xí)筆記(一):nginx的安裝和配置

以上就是Windows下Nginx的安裝及配置實(shí)例講解的詳細(xì)內(nèi)容,更多請(qǐng)關(guān)注php中文網(wǎng)其它相關(guān)文章!

 
關(guān)鍵詞: Windows,Nginx,實(shí)例
 
[ 資訊搜索 ]  [ 加入收藏 ]  [ 告訴好友 ]  [ 打印本文 ]  [ 違規(guī)舉報(bào) ]  [ 關(guān)閉窗口 ]

 
0條 [查看全部]  相關(guān)評(píng)論

 
網(wǎng)站首頁(yè) | 關(guān)于我們 | 聯(lián)系方式 | 使用協(xié)議 | 版權(quán)隱私 | 網(wǎng)站地圖 | 排名推廣 | 廣告服務(wù) | 積分換禮 | 網(wǎng)站留言 | RSS訂閱 | 吉ICP備11001726號(hào)-6
企業(yè)800網(wǎng) · 提供技術(shù)支持