国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Nginx配置http和https

這篇具有很好參考價值的文章主要介紹了Nginx配置http和https。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

配置文件 默認放置位置:{nginx}/conf.d/,以conf結(jié)尾

一、http簡單配置

server {
        listen       80;
        server_name  www.test.cn;
        root /mnt/website/ROOT;
        
        if ( $query_string ~* ".*[;'<>].*" ){
            return 404;
        }
        if ( $query_string ~* ".*script.*" ){
            return 404;
        }
 
        location ~* ^/WEB-INF/.*$
        {
         deny all;
        }

        location ~* ^/(UserFiles|userfiles|images|Images|upload)/.*\.(jsp|js)$
        {
         deny all;
        }

        location / {
             proxy_set_header Host $host;
             proxy_set_header X-Real-IP $remote_addr;
             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
             proxy_pass   http://127.0.0.1:8888;
        }
}
server{
	server_name test.cn;
	root /mnt/website/ROOT;
	location ^~ / {
             rewrite ^(.*) http://www.test.cn$1 permanent;
        }
}

說明:

1,http默認端口是80

2,http://127.0.0.1:8888;為實際本地服務(wù)端口

3,一般服務(wù)域名為二級域名www,一級域名一般也配置指向www域名。

二、https配置

首先得申請ssl證書,百度,阿里都有免費證書可用,申請成功后,下載nginx壓縮包,解壓后,可見兩種后綴文件,一個是xxx.key,另一個是xxx.crt,或者是xxx.pem。文件名可以隨意更改,一般改為域名。

其次是配置文件配置

server {
        listen       443;
        server_name  www.test.cn;
        root /mnt/website/ROOT;
	     ssl                  on;
       ssl_certificate      /etc/nginx/ssl/www.test.cn.crt;
       ssl_certificate_key      /etc/nginx/ssl/www.test.cn.key;
       ssl_session_timeout  5m;
       ssl_protocols  SSLv3 TLSv1;
       ssl_ciphers  HIGH:!ADH:!EXPORT56:RC4+RSA:+MEDIUM;
       ssl_prefer_server_ciphers   on;


        if ( $query_string ~* ".*[;'<>].*" ){
        return 404;
        }
        if ( $query_string ~* ".*script.*" ){
        return 404;
        }

        location ~* ^/imgPath/.*$
        {
         rewrite ^/imgPath(.*) http://img.test.cn/imgPath$1 last;
        }
      
        location ~* ^/WEB-INF/.*$
        {
         deny all;
        }

        location ~* ^/(UserFiles|userfiles|images|Images|upload)/.*\.(jsp|js)$
        {
         deny all;
        }
        location / {

            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass   http://127.0.0.1:8888;
        }
}

說明:

1,https端口為443,此端口不是服務(wù)器默認開放端口,需要單獨打開。

2,ssl文件放置正確即可。crt文件換成pem文件亦可。

3,資源文件路徑可指向其他域名,可見location ~* ^/imgPath/.*$這段

三、單域名指向本地不同服務(wù),以https配置為例

upstream shop {
   server 127.0.0.1:7777;
}

server {
        listen       443;
        server_name  www.test.cn;
        root /mnt/website/ROOT;
	 ssl                  on;
       ssl_certificate      /etc/nginx/ssl/www.test.cn.crt;
       ssl_certificate_key      /etc/nginx/ssl/www.test.cn.key;
       ssl_session_timeout  5m;
       ssl_protocols  SSLv3 TLSv1;
       ssl_ciphers  HIGH:!ADH:!EXPORT56:RC4+RSA:+MEDIUM;
       ssl_prefer_server_ciphers   on;


        if ( $query_string ~* ".*[;'<>].*" ){
        return 404;
        }
        if ( $query_string ~* ".*script.*" ){
        return 404;
        }

        location ~* ^/imgPath/.*$
        {
         rewrite ^/imgPath(.*) http://img.test.cn/imgPath$1 last;
        }
      
        location ~* ^/WEB-INF/.*$
        {
         deny all;
        }

        location ~* ^/(UserFiles|userfiles|images|Images|upload)/.*\.(jsp|js)$
        {
         deny all;
        }
        location / {

            rewrite ^(.*) https://www.test.com$1 permanent;
        }

location /shop/ {
proxy_pass http://shop;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 300;
proxy_send_timeout 300;
proxy_read_timeout 300;
proxy_buffer_size 128k;
proxy_buffers 2 256k;
proxy_busy_buffers_size 256k;
proxy_temp_file_write_size 256k;
}
    }

說明:

1,upstream shop,shop只能出現(xiàn)一次

2,可以是本地服務(wù),亦可是其他ip服務(wù),127.0.0.1換成對應(yīng)ip即可

3,location /shop/ ,此塊必須在server的區(qū)塊內(nèi),/shop/為訪問路徑,即https://www.test.cn/shop/xxx,為訪問路徑文章來源地址http://www.zghlxwxcb.cn/news/detail-405507.html

到了這里,關(guān)于Nginx配置http和https的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • nginx配置http請求轉(zhuǎn)成https請求

    1、return 301 2、rewitre 3、error_page 原理: http和https是tcp的上層協(xié)議,當(dāng)nginx服務(wù)器建立tcp連接后,根據(jù)收到的第一份數(shù)據(jù)來確定客戶端是希望建立tls還是http。nginx會判斷tcp請求的首寫節(jié)內(nèi)容以進行區(qū)分,如果是0x80或者0x16就可能是ssl或者tls,然后嘗試https握手。如果端口開啟了

    2024年02月07日
    瀏覽(21)
  • Nginx同時支持Http和Https的配置詳解

    當(dāng)配置Nginx同時支持HTTP和HTTPS時,需要進行以下步驟: 獲得SSL證書:從可信任的證書頒發(fā)機構(gòu)(CA)或使用自簽名證書創(chuàng)建SSL證書。 將證書和私鑰保存到服務(wù)器:將SSL證書和私鑰文件保存到指定的位置,通常是 /etc/nginx/ssl/ 目錄。 配置HTTP服務(wù): 打開 Nginx 配置文件: 通常是

    2024年02月02日
    瀏覽(21)
  • Nginx配置springboot+vue項目http跳轉(zhuǎn)https

    Nginx配置springboot+vue項目http跳轉(zhuǎn)https

    java生成證書 添加依賴 復(fù)制keystore到springboot資源目錄,修改application.yml配置 ?啟動項目 nginx配置 開啟ssl ? ? 重啟nginx -s reload 訪問localhost:81將跳轉(zhuǎn)到https://localhost/login?redirect=/index ?

    2024年02月12日
    瀏覽(24)
  • nginx 同一個端口支持http和https配置

    原理:使用nginx的stream、 stream_ssl_preread模塊 1.編譯nginx 由于stream和stream_ssl_preread模塊非默認引入,需要在編譯安裝nginx時引入;編譯時添加配置參數(shù) --with-stream --with-stream_ssl_preread_module ./configure --prefix=/usr/local/nginx?--with-http_ssl_module --with-http_stub_status_module --with-stream --with-stre

    2024年02月10日
    瀏覽(20)
  • Nginx配置同時支持http和https兩種方式訪問

    Nginx配置同時支持http和https兩種方式訪問

    http: https: Nginx的ssl模塊安裝 進入到目錄的sbin目錄下,輸入 如果出現(xiàn) (configure arguments: --with-http_ssl_module), 則已安裝(下面的步驟可以跳過,直接進行第五步)。 一般情況下都是不存在ssl模塊的,接下來進入到你的解壓縮后的nginx目錄,注意這里不是nginx安裝目錄,是解壓縮后

    2024年02月13日
    瀏覽(23)
  • nginx的同一個端口配置支持http與https協(xié)議

    http://www.baidu.com:5000 https://www.baidu.com:5000 請求自定義端口的http 跟https,都一樣的頁面 vim /opt/lucky/nginx/conf/vhosts/baidu.conf

    2024年02月13日
    瀏覽(88)
  • Nginx配置https網(wǎng)站訪問第三方節(jié)點的http資源

    https網(wǎng)站無法直接下載http網(wǎng)站的文件。解決思路有以下幾種情況:1.兩個網(wǎng)站都同時改為http或https。2.通過nginx轉(zhuǎn)發(fā)。3.通過后端java代碼獲取對方網(wǎng)站的文件流然后把流返回給前端 本文介紹如果通過nginx轉(zhuǎn)發(fā)訪問http網(wǎng)站 配置規(guī)則一: 這樣配置之后,本地網(wǎng)站比如是:訪問htt

    2024年02月16日
    瀏覽(26)
  • Minio nginx配置https和http問題解決,疑難癥全網(wǎng)首發(fā)

    Minio nginx配置https和http問題解決,疑難癥全網(wǎng)首發(fā)

    進入下面小程序可以體驗效果 : ? 以下問題基本上是因為NGINX代理出現(xiàn) 一、API直接返回單獨的錯誤: io.minio.errors.ErrorResponseException: Access denied 二、API直接返回的錯誤:The request signature we calculated does not match the si 三、預(yù)覽文件或者圖片返回錯誤 以上三個問題都屬于Access den

    2024年02月13日
    瀏覽(26)
  • nginx配置若依框架vue打包項目(同時支持http和https)

    該配置模版主要是若依框架前后端配置,若只是配置普通的vue項目,直接復(fù)制一下小模塊即可 ? #vue頁面訪問配置 ? ? ?location ?/ { ? ? ? ? ? ? ?root /www/wwwroot/www.xxx.com; ? ? ? ? ? ? # autoindex on; ? ? ? ? ? ? ?try_files $uri $uri/ /index.html; ? ? ? ? ? ? ?index ?index.html index.htm

    2024年01月25日
    瀏覽(20)
  • SpringBoot+Vue前后端分離項目+云服務(wù)器(nginx配置http/https)

    SpringBoot+Vue前后端分離項目+云服務(wù)器(nginx配置http/https)

    目錄 1.Java項目打包 2.前端項目打包 ok,項目準(zhǔn)備好了,接下來就是服務(wù)器方面的操作了 3.服務(wù)器 1.點擊控制臺 2.找到 ECS云服務(wù)器 3.概覽-我的資源 ?4.重置服務(wù)器密碼 ?5.配置安全組 4.域名 1.買域名 2.備案? 3.解析至服務(wù)器 31.控制臺找到 ?3.2.域名列表 ,找到需要的域名,點擊解析?

    2024年02月09日
    瀏覽(19)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包