日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

nginx实现301(加密)跳转和200跳转

發(fā)布時間:2023/12/10 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 nginx实现301(加密)跳转和200跳转 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

? ? ? ?我們用nginx實現(xiàn)301跳轉(zhuǎn),下面我們先講一下實現(xiàn)的大概思想,首先我們用yum或者編譯安裝nginx,然后配置nginx的主配置文件的子文件,(在配置子文件的時候可以把默認(rèn)文件先注釋掉)配置好子文件之后重啟nginx服務(wù)器。然后就可以去測試你想要的結(jié)果啦。(前提是把防火墻關(guān)掉,例如:selinux、firewalld、iptables等一切的環(huán)境)

第一步:清理環(huán)境

1:首先查看firewalld的狀態(tài)

# systemctl status friewalld

沒有關(guān)閉,要關(guān)閉firewalld

systemctl disable firewalld

2:查看selinux的狀態(tài)

# getenforce(顯示enforcing是開啟的狀態(tài),顯示disable是關(guān)閉的狀態(tài))

沒有關(guān)閉則編輯vim /etc/selinux/conf

把selinux=enforcing改成selinux=disabled(重啟后生效)

3:查看iptables的狀態(tài)

# systemctl status iptables

把iptables的規(guī)則全部清理掉

# iptables -F

# iptables -F -t nat

# iptables -F -t mangle

之后把iptables關(guān)閉

# systemctl stop iptables

# systemctl disable iptables

4:關(guān)閉networkmanager

# systemctl status NetworkManager

# systemctl stop NetworkManager

# systemctl disable NetworkManager

第二步y(tǒng)um安裝nginx

(首先要有epel源,下載epel源

# yum install -y epel-release

# yum makecache

)然后就可以下載nginx服務(wù)了

# yum install -y nginx

啟動nginx

# systemctl start nginx

第三步:配置nginx主配置文件

# vim /etc/nginx/nginx.conf

?

把include /etc/nginx/conf/*.conf下面的子文件都注釋掉,按wq保存退出

? ? ? 之后進(jìn)入/etc/nginx.conf,編輯一個子文件

例如:vim ?1.conf

編輯好之后保存退出。

意思就是:當(dāng)你訪問192.168.213.133時,網(wǎng)頁將會跳轉(zhuǎn)到https://www.taobao.com

第四步:測試

? ? ? 用nginx -t 檢查文件有沒有編輯錯誤,再看一下80服務(wù)有沒有開啟,用losf -i:80判斷無誤之后, 重啟服務(wù)systemctl restart nginx。然后就可以在網(wǎng)頁上輸入自己設(shè)定的IP加端口號進(jìn)行訪問了,這就實現(xiàn)了301加密跳轉(zhuǎn)。

實現(xiàn)200普通跳轉(zhuǎn)

步驟和上面的一樣就是配置文件不一樣,如果實現(xiàn)普通跳轉(zhuǎn),還要加一步,就是編寫你要在網(wǎng)頁訪問到的內(nèi)容

# cd /var/www/html

# vim 2.html

?編寫您要的內(nèi)容

然后就可以在網(wǎng)頁上訪問啦。(在訪問的時候一定要加后面的目錄哦,例如:192.168.213.133/2.html)

?帶有域名的301跳轉(zhuǎn) ?

?1)帶有數(shù)據(jù)庫有后臺的網(wǎng)站實現(xiàn)301跳轉(zhuǎn)判斷

例:域名是5773.com , 網(wǎng)站是vns_hb.com,網(wǎng)站放到/wz這個文件夾的目錄下

# vim 1.conf

  server {

    listen     ?80 ;
    server_name  5773.com www.5773.com;
    charset     ?utf-8;

   location / {

    root   ? ? ? ? ? ? ??/wz/vns_hb.com;
    index   ? ? ? ? ? ??index.html index.htm index.php;
    }

    error_page ?404 /404.html;
    location = ?/40x.html {
    }
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
    }

    location ~ \.php$ {
    root /wz/vns_hb.com;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    }
    }

保存退出。

重啟一下nginx

# systemctl ? reload ?nginx

2)帶有證書的網(wǎng)站實現(xiàn)301跳轉(zhuǎn)的判斷

例:域名是1778.com ,網(wǎng)站是1778.com ,網(wǎng)站放到/wz文件夾的目錄下

# vim 1.conf

  server {
    listen 80 ;
    listen 443 ssl;
    server_name 1778.com www.1778.com;
    charset utf-8;
    index index.html;
    root /wz/1778.com;
    if ($scheme = http ) {
    return 301 https://$host$request_uri;
    }
    ssl_certificate_key /etc/nginx/conf/1778/Nginx/2_1778.com.key;
    ssl_certificate /etc/nginx/conf/1778/Nginx/1_1778.com_bundle.crt;

    # Load configuration files for the default server block.
    include /etc/nginx/default.d/*.conf;

    location / {
    }
    location ~ \.php$ {
    root /wz/1778.com;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    }
    }

保存退出

重啟一下nginx

# systemctl reload nginx

3)沒有證書沒有數(shù)據(jù)庫,但是輸入https還能正常跳轉(zhuǎn) ?

例:域名是1655.com ,網(wǎng)站是1655.com , 存放網(wǎng)站目錄是/wz

# vim 1.conf

  server {
    listen 80 ;

    listen 443;
    server_name 1655.com www.1655.com;
    charset utf-8;
    #if ($scheme = https ) {
    return 301 http://$host$request_uri;
    #}

    location / {
    root /wz/1655.com;
    index index.html index.htm index.php;
    }

    error_page 404 /404.html;
    location = /40x.html {
    }
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
    }

    location ~ \.php$ {
    root /wz/1655.com;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    }
    }

?保存退出。

重啟一下nginx

# systemctl reload nginx

4)實現(xiàn)多域名跳轉(zhuǎn)

例:域名7788110.com~7788511.cc等域名 ,網(wǎng)站是7788990.com , 網(wǎng)站目錄/wz

# vim 1.conf

  server {

    listen  80;

    listen  443;

    charset  utf8;

    server_name 7788110.com www.7788110.com 7788220.com www.7788220.com 7788330.com www.7788330.com 7788440.com www.7788440.com 7788550.com www.7788550.com 7788660.com www.7788660.com 7788770.com www.7788770.com 7788880.cocm www.7788880.com 7788210.net www.7788210.net 7788660.net www.7788660.net 7788511.cc www.7788511.cc;

    root  /wz/7788990.com;

    index  index.html index.htm index.php;   

    # if ($server_port = 80 ) {
    return 301 https://www.7788990.com$request_uri;
    rewrite ^/[0-9a-zA-Z]+$ https://www.7788990.com/ break;
    # }

    # Load configuration files for the default server block.
    include /etc/nginx/default.d/*.conf;

    location / {
    }
    location ~ \.php$ {
    root /wz/7788990.com;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    }
    }

保存退出。

重啟一下nginx

# systemctl reload nginx

5)實現(xiàn)用戶輸入域名后綴是ID和TYPE來訪問網(wǎng)站實現(xiàn)301跳轉(zhuǎn)

例:域名chnnowm.com ,要跳轉(zhuǎn)的網(wǎng)站是232xinyi.com ,?

# vim 1.conf

  server {

    listen  80;

    charset  utf8;

    server_name  chnnowm.com www.chnnowm.com;

    index  index.html index.htm;

    if ($arg_typ = 'xytb' ) {
    return 301 https://232xinyi.com:8888/Reqister?a=$arg_ID;
    }
    ? ssl_certificate_key /etc/nginx/conf/chnnowm.com/Nginx/2_chnnowm.com.key;
    ??ssl_certificate/etc/nginx/conf/chnnowm/Nginx/1_chnnowm.com_bundle.crt;

    include /etc/nginx/default.d/*.conf;

?

    location / {
    }
    location ~ \.php$ {
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    }
    }

保存退出。

重啟一下nginx

# systemctl reload nginx

讓問的時候直接域名+ID+TYPE(例如:https://www.chnnowm.com?ID=706787&type=xytb

 

?

轉(zhuǎn)載于:https://www.cnblogs.com/ping-7/p/7894843.html

總結(jié)

以上是生活随笔為你收集整理的nginx实现301(加密)跳转和200跳转的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。