찾다
운영 및 유지보수엔진스nginx에서 의사 정적을 구성하고 클라이언트를 조정하는 방법

后端用的thinkphp3.2.3框架,如果您是其他的语言或者,注意适当修改下

server {
    listen    80;
    server_name www.morgen.club;

    #charset koi8-r;
    
    #access_log logs/host.access.log main;

网站根目录

location / {
      root  html;
      index index.html index.htm;
      #设置访问设备
      set $source_device 'index';
      #判断为手机客户端或ipad
      if ($http_user_agent ~* (mobile|nokia|iphone|ipad|android|samsung|htc|blackberry)) {
        set $source_device 'phone';
      }
      #根目录
      if ($request_uri ~* ^/$){
        rewrite ^(.*)$ /index.php?s=/home/$source_device/index.html last;
        break;
      }
      #电脑首页
      if ($request_uri ~* ^/home/index/index.html$) {
        rewrite ^/home/index/index.html$ /web/ permanent;
        break;
      }
      #电脑首页分页
      if ($request_uri ~* ^/home/index/index/page/(\d*).html$) {
        rewrite ^/home/index/index/page/(\d*).html$ /web/pages/$1/ permanent;
        break;
      }
      #电脑首页分类首页
      if ($request_uri ~* ^/home/index/index/cate/(\d*).html$) {
        rewrite ^/home/index/index/cate/(\d*).html$ /web/cates/$1/ permanent;
        break;
      }
      #电脑首页分类分页
      if ($request_uri ~* ^/home/index/index/cate/(\d*)/page/(\d*).html$) {
        rewrite ^/home/index/index/cate/(\d*)/page/(\d*).html$ /web/cates/$1/pages/$2/ permanent;
        break;
      }
      #电脑首页搜索
      if ($request_uri ~* ^/home/index/index.html(.*)) {
        rewrite ^/home/index/index.html(.*) /web/search?$query_string permanent;
        break;
      }
      #电脑书籍页面
      if ($request_uri ~* ^/home/index/books/book/(\d*).html$) {
        rewrite ^/home/index/books/book/(\d*).html$ /web/books/$1/ permanent;
        break;
      }
      #电脑章节页面
      if ($request_uri ~* ^/home/index/contents/books/(\d*)/chapters/(\d*).html$) {
        rewrite ^/home/index/contents/books/(\d*)/chapters/(\d*).html$ /web/books/$1/chapters/$2/ permanent;
        break;
      }
      #手机首页
      if ($request_uri ~* ^/home/phone/index.html$) {
        rewrite ^/home/phone/index.html$ /phone/ last;
        break;
      }
      #手机首页分页
      if ($request_uri ~* ^/home/phone/index/page/(\d*)(.*)$) {
        rewrite ^/home/phone/index/page/(\d*).html /phone/pages/$1/ permanent;
        break;
      }
      #手机首页分类首页
      if ($request_uri ~* ^/home/phone/index/cate/(\d*).html$) {
        rewrite ^/home/phone/index/cate/(\d*).html$ /phone/cates/$1/ permanent;
        break;
      }
      #手机首页分类分页
      if ($request_uri ~* ^/home/phone/index/cate/(\d*)/page/(\d*).html$) {
        rewrite ^/home/phone/index/cate/(\d*)/page/(\d*).html$ /phone/cates/$1/pages/$2/ permanent;
        break;
      }
      #手机首页搜索
      if ($request_uri ~* ^/home/phone/index.html?(.*)) {
        rewrite ^/home/phone/index.html(.*) /phone/index.html$1 permanent;
        break;
      }
      #手机书籍页面
      if ($request_uri ~* ^/home/phone/books/book/(\d*).html$) {
        rewrite ^/home/phone/books/book/(\d*).html$ /phone/books/$1/ permanent;
        break;
      }
      #手机章节页面
      if ($request_uri ~* ^/home/phone/contents/books/(\d*)/chapters/(\d*).html$) {
        rewrite ^/home/phone/contents/books/(\d*)/chapters/(\d*).html$ /phone/books/$1/chapters/$2/ permanent;
        break;
      }
      
      if ($request_uri ~* ^/home/book/(.*)$) {
        rewrite ^(.*)$ /index.php?s=$1 last;
        break;
      }

      if (!-e $request_filename) {
        return 404;
      }
    }

电脑浏览器端

location /web {
      root html;
      index index.html index.htm;
      #如果设备为手机或ipad
      if ($http_user_agent ~* (mobile|nokia|iphone|ipad|android|samsung|htc|blackberry)) {
        rewrite ^/web(.*) /phone$1 permanent;
      }
        #电脑首页搜索
        if ($request_uri ~ ^/web/search(.*)$) {
          rewrite ^(.*) /index.php?s=/home/index/index.html last;
          break;
        }
        #电脑首页
        set $index false;
        if ($request_uri ~* ^/web$) {
          set $index true;
        }
        if ($request_uri ~* ^/web/$) {
          set $index true;
        }
        if ($index = true){
          rewrite ^/web(.*) /index.php?s=/home/index/index.html last;
          break;
        }
        #电脑首页分页
        set $index_page false;
        if ($request_uri ~* ^/web/pages/(\d*)$) {
          set $index_page true;
        }
        if ($request_uri ~* ^/web/pages/(\d*)/$) {
          set $index_page true;
        }
        if ($index_page = true){
          rewrite ^/web/pages/(\d*)(.*) /index.php?s=/home/index/index/page/$1.html last;
          break;
        }
        #电脑分类首页
        set $cate false;
        if ($request_uri ~* ^/web/cates/(\d*)$) {
          set $cate true;
        }
        if ($request_uri ~* ^/web/cates/(\d*)/$) {
          set $cate true;
        }
        if ($cate = true){
          rewrite ^/web/cates/(\d*)(.*) /index.php?s=/home/index/index/cate/$1.html last;
          break;
        }
        #电脑分类分页
        set $cate_page false;
        if ($request_uri ~* ^/web/cates/(\d*)/pages/(\d*)$) {
          set $cate_page true;
        }
        if ($request_uri ~* ^/web/cates/(\d*)/pages/(\d*)/$) {
          set $cate_page true;
        }
        if ($cate_page = true){
          rewrite ^/web/cates/(\d*)/pages/(\d*)(.*) /index.php?s=/home/index/index/cate/$1/page/$2.html last;
          break;
        }
        
        #电脑书籍页面
        set $book false;
        if ($request_uri ~* ^/web/books/(\d*)$) {
          set $book true;
        }
        if ($request_uri ~* ^/web/books/(\d*)/$) {
          set $book true;
        }
        if ($book = true){
          rewrite ^/web/books/(\d*)(.*) /index.php?s=/home/index/books/book/$1.html last;
          break;
        }
        #电脑章节页面
        set $chapter false;
        if ($request_uri ~* ^/web/books/(\d*)/chapters/(.*)$) {
          set $chapter true;
        }
        if ($request_uri ~* ^/web/books/(\d*)/chapters/(.*)/$) {
          set $chapter true;
        }
        if ($chapter = true){
          rewrite ^/web/books/(\d*)/chapters/(.*)/ /index.php?s=/home/index/contents/books/$1/chapters/$2.html last;
          break;
        }

        if (!-e $request_filename) {
          return 404;
        }
    }

手机和平板端

location /phone {
      root html;
      index index.html index.htm;
      #如果设备不是手机或ipad
      if ($http_user_agent !~* (mobile|nokia|iphone|ipad|android|samsung|htc|blackberry)) {
        rewrite ^/phone(.*) /web$1 permanent;
      }
        #电脑首页搜索
        if ($request_uri ~ ^/phone/search(.*)$) {
          rewrite ^(.*) /index.php?s=/home/phone/index.html last;
          break;
        }
        #手机首页
        set $index false;
        if ($request_uri ~* ^/phone$) {
          set $index true;
        }
        if ($request_uri ~* ^/phone/$) {
          set $index true;
        }
        if ($index = true){
          rewrite ^/phone(.*) /index.php?s=/home/phone/index.html last;
          break;
        }
        #手机首页分页
        set $index_page false;
        if ($request_uri ~* ^/phone/pages/(\d*)$) {
          set $index_page true;
        }
        if ($request_uri ~* ^/phone/pages/(\d*)/$) {
          set $index_page true;
        }
        if ($index_page = true){
          rewrite ^/phone/pages/(\d*)(.*) /index.php?s=/home/phone/index/page/$1.html last;
          break;
        }
        #手机分类首页
        set $cate false;
        if ($request_uri ~* ^/phone/cates/(\d*)$) {
          set $cate true;
        }
        if ($request_uri ~* ^/phone/cates/(\d*)/$) {
          set $cate true;
        }
        if ($cate = true){
          rewrite ^/phone/cates/(\d*) /index.php?s=/home/phone/index/cate/$1.html last;
          break;
        }
        #手机分类分页
        set $cate_page false;
        if ($request_uri ~* ^/phone/cates/(\d*)/pages/(\d*)$) {
          set $cate_page true;
        }
        if ($request_uri ~* ^/phone/cates/(\d*)/pages/(\d*)/$) {
          set $cate_page true;
        }
        if ($cate_page = true){
          rewrite ^/phone/cates/(\d*)/pages/(\d*)(.*) /index.php?s=/home/phone/index/cate/$1/page/$2.html last;
          break;
        }
        #手机书籍页面
        set $book false;
        if ($request_uri ~* ^/phone/books/(\d*)$) {
          set $book true;
        }
        if ($request_uri ~* ^/phone/books/(\d*)/$) {
          set $book true;
        }
        if ($book = true){
          rewrite ^/phone/books/(\d*)(.*) /index.php?s=/home/phone/books/book/$1.html last;
          break;
        }
        #手机书籍分页页面
        set $book false;
        if ($request_uri ~* ^/phone/books/(\d*)/pages/(\d*)$) {
          set $book true;
        }
        if ($request_uri ~* ^/phone/books/(\d*)/pages/(\d*)/$) {
          set $book true;
        }
        if ($book = true){
          rewrite ^/phone/books/(\d*)/pages/(\d*) /index.php?s=/home/phone/books/book/$1/page/$2.html last;
          break;
        }
        #手机章节页面
        set $chapter false;
        if ($request_uri ~* ^/phone/books/(\d*)/chapters/(.*)$) {
          set $chapter true;
        }
        if ($request_uri ~* ^/phone/books/(\d*)/chapters/(.*)/$) {
          set $chapter true;
        }
        if ($chapter = true){
          rewrite ^/phone/books/(\d*)/chapters/(.*)/ /index.php?s=/home/phone/contents/books/$1/chapters/$2.html last;
          break;
        }

        if (!-e $request_filename) {
          return 404;
        }
    }
    location ~ .xml(.*) {
      root html/ttt/;
    }
 
    location ~ .txt(.*) {
      root html/ttt/;
    }
    location ~ .gif(.*) {
      root html/ttt/;
    }
    location ~ .jpg(.*) {
      root html/ttt/;
    }
    location ~ .css(.*) {
      root html/ttt/;
    }
    location ~ .js$ {
      root html/ttt/;
    }
    location ~ .php$ {
      root html/ttt;
      fastcgi_pass 127.0.0.1:9000;
      fastcgi_index index.php;
      fastcgi_buffers 8 256k;
      fastcgi_connect_timeout 300s;
      fastcgi_send_timeout 300s;
      fastcgi_read_timeout 300s;
      fastcgi_param script_filename $document_root$fastcgi_script_name;
      include fastcgi_params;
    }
  }

위 내용은 nginx에서 의사 정적을 구성하고 클라이언트를 조정하는 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명
이 기사는 亿速云에서 복제됩니다. 침해가 있는 경우 admin@php.cn으로 문의하시기 바랍니다. 삭제
Nginx vs. Apache : 웹 호스팅 및 트래픽 관리Nginx vs. Apache : 웹 호스팅 및 트래픽 관리Apr 12, 2025 am 12:04 AM

NGINX는 동시성이 높은 자원 소비 시나리오에 적합하지만 APACHE는 복잡한 구성 및 기능 확장이 필요한 시나리오에 적합합니다. 1.NGINX는 고성능과의 많은 동시 연결을 처리하는 것으로 알려져 있습니다. 2. Apache는 안정성과 풍부한 모듈 지원으로 유명합니다. 선택할 때는 특정 요구에 따라 결정해야합니다.

NGINX : 최신 웹 애플리케이션을위한 다목적 도구NGINX : 최신 웹 애플리케이션을위한 다목적 도구Apr 11, 2025 am 12:03 AM

nginxissentialderformodernwebapplicationsduetoitsrolessareareverseproxy, loadbalancer 및 Webserver, HighperformanceAndscalability를 제공합니다

Nginx SSL/TLS 구성 : HTTPS로 웹 사이트 보안Nginx SSL/TLS 구성 : HTTPS로 웹 사이트 보안Apr 10, 2025 am 09:38 AM

Nginx를 통해 웹 사이트 보안을 보장하려면 다음 단계가 필요합니다. 1. 기본 구성을 만들고 SSL 인증서 및 개인 키를 지정하십시오. 2. 구성 최적화, HTTP/2 및 OCSPStapling 활성화; 3. 인증서 경로 및 암호화 제품군 문제와 같은 공통 오류 디버그; 4. Let 'sencrypt 및 세션 멀티플렉싱 사용과 같은 응용 프로그램 성능 최적화 제안.

Nginx 인터뷰 질문 : ACE 귀하의 DevOps/System Admin 인터뷰Nginx 인터뷰 질문 : ACE 귀하의 DevOps/System Admin 인터뷰Apr 09, 2025 am 12:14 AM

NGINX는 고성능 HTTP 및 리버스 프록시 서버로 높은 동시 연결을 처리하는 데 능숙합니다. 1) 기본 구성 : 포트를 듣고 정적 파일 서비스를 제공합니다. 2) 고급 구성 : 리버스 프록시 및로드 밸런싱을 구현하십시오. 3) 디버깅 기술 : 오류 로그를 확인하고 구성 파일을 테스트하십시오. 4) 성능 최적화 : GZIP 압축을 활성화하고 캐시 정책을 조정합니다.

Nginx 캐싱 기술 : 웹 사이트 성능 향상Nginx 캐싱 기술 : 웹 사이트 성능 향상Apr 08, 2025 am 12:18 AM

Nginx 캐시는 다음 단계를 통해 웹 사이트 성능을 크게 향상시킬 수 있습니다. 1) 캐시 영역을 정의하고 캐시 경로를 설정하십시오. 2) 캐시 유효성 기간 구성; 3) 다른 컨텐츠에 따라 다른 캐시 정책을 설정합니다. 4) 캐시 저장 및로드 밸런싱을 최적화합니다. 5) 캐시 효과를 모니터링하고 디버그합니다. 이러한 방법을 통해 NGINX 캐시는 백엔드 서버 압력을 줄이고 응답 속도 및 사용자 경험을 향상시킬 수 있습니다.

Docker와 Nginx : 컨테이너화 된 응용 프로그램을 배포하고 스케일링합니다Docker와 Nginx : 컨테이너화 된 응용 프로그램을 배포하고 스케일링합니다Apr 07, 2025 am 12:08 AM

dockercompose를 사용하면 Nginx의 배포 및 관리를 단순화 할 수 있으며 Dockerswarm 또는 Kubernetes를 통한 스케일링은 일반적인 관행입니다. 1) DockerCompose를 사용하여 Nginx 컨테이너를 정의하고 실행하십시오. 2) Dockerswarm 또는 Kubernetes를 통한 클러스터 관리 및 자동 스케일링 구현.

고급 NGINX 구성 : 서버 블록 마스터 링 및 리버스 프록시고급 NGINX 구성 : 서버 블록 마스터 링 및 리버스 프록시Apr 06, 2025 am 12:05 AM

NGINX의 고급 구성은 서버 블록 및 리버스 프록시를 통해 구현 될 수 있습니다. 1. 서버 블록을 사용하면 여러 웹 사이트를 한쪽으로 실행할 수있게되면 각 블록은 독립적으로 구성됩니다. 2. 리버스 프록시는 요청을 백엔드 서버로 전달하여로드 밸런싱 및 캐시 가속도를 실현합니다.

Nginx 성능 튜닝 : 속도 및 낮은 대기 시간을 최적화합니다Nginx 성능 튜닝 : 속도 및 낮은 대기 시간을 최적화합니다Apr 05, 2025 am 12:08 AM

작업자 프로세스 수, 연결 풀 크기, GZIP 압축 및 HTTP/2 프로토콜을 활성화하고 캐시 및로드 밸런싱을 사용하여 NGINX 성능 튜닝을 달성 할 수 있습니다. 1. 작업자 프로세스 수 및 연결 풀 크기 조정 : Worker_ProcessesAuto; 이벤트 {worker_connections1024;}. 2. GZIP 압축 및 HTTP/2 프로토콜 활성화 : http {gzipon; server {listen443sslhttp2;}}. 3. 캐시 최적화 사용 : http {proxy_cache_path/path/to/cachelevels = 1 : 2k

See all articles

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

AI Hentai Generator

AI Hentai Generator

AI Hentai를 무료로 생성하십시오.

인기 기사

R.E.P.O. 에너지 결정과 그들이하는 일 (노란색 크리스탈)
3 몇 주 전By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. 최고의 그래픽 설정
3 몇 주 전By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. 아무도들을 수없는 경우 오디오를 수정하는 방법
3 몇 주 전By尊渡假赌尊渡假赌尊渡假赌
WWE 2K25 : Myrise에서 모든 것을 잠금 해제하는 방법
4 몇 주 전By尊渡假赌尊渡假赌尊渡假赌

뜨거운 도구

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경

WebStorm Mac 버전

WebStorm Mac 버전

유용한 JavaScript 개발 도구

맨티스BT

맨티스BT

Mantis는 제품 결함 추적을 돕기 위해 설계된 배포하기 쉬운 웹 기반 결함 추적 도구입니다. PHP, MySQL 및 웹 서버가 필요합니다. 데모 및 호스팅 서비스를 확인해 보세요.

SublimeText3 Linux 새 버전

SublimeText3 Linux 새 버전

SublimeText3 Linux 최신 버전

메모장++7.3.1

메모장++7.3.1

사용하기 쉬운 무료 코드 편집기