aizu's Knowledge Base
    • Go to: aizu.my Homepage
    • Recent
    • Tags
    • Register
    • Login

    nginx conf - sample

    Linux
    1
    3
    152
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A
      aizu
      last edited by aizu

      upstream _backend {
        server 127.0.0.1:81;
      }
      
      server {
        client_max_body_size 100M;
        listen 80 default_server;
        server_name domain.com;
        client_max_body_size 100M;
        error_log  /var/log/nginx/domain.com-error.log;
        access_log /var/log/nginx/domain.com-access.log;
      
        if ($http_user_agent ~* "curl|wget|SemrushBot|Semrush|AhrefsBot|MJ12bot|YandexBot|YandexImages|MegaIndex.ru|BLEXbot|BLEXBot|ZoominfoBot|YaK|VelenPublicWebCrawler|SentiBot|Vagabondo|SEOkicks|SEOkicks-Robot|mtbot/1.1.0i|SeznamBot|DotBot|Cliqzbot|coccocbot|python|Scrap|SiteCheck-sitecrawl|MauiBot|Java|GumGum|Clickagy|AspiegelBot|Yandex|TkBot|CCBot|Qwantify|MBCrawler|serpstatbot|AwarioSmartBot|Semantici|ScholarBot|proximic|MojeekBot|GrapeshotCrawler|IAScrawler|linkdexbot|contxbot|PlurkBot|PaperLiBot|BomboraBot|Leikibot|weborama-fetcher|NTENTbot|Screaming Frog SEO Spider|admantx-usaspb|Eyeotabot|VoluumDSP-content-bot|SirdataBot|adbeat_bot|TTD-Content|admantx|Nimbostratus-Bot|Mail.RU_Bot|Quantcastboti|Onespot-ScraperBot|Taboolabot|Baidu|Jobboerse|VoilaBot|Sogou|Jyxobot|Exabot|ZGrab|Proximi|Sosospider|Accoona|aiHitBot|Genieo|BecomeBot|ConveraCrawler|NerdyBot|OutclicksBot|findlinks|JikeSpider|Gigabot|CatchBot|Huaweisymantecspider|Offline Explorer|SiteSnagger|TeleportPro|WebCopier|WebReaper|WebStripper|WebZIP|Xaldon_WebSpider|BackDoorBot|AITCSRoboti|Arachnophilia|BackRub|BlowFishi|perl|CherryPicker|CyberSpyder|EmailCollector|Foobot|GetURL|httplib|HTTrack|LinkScan|Openbot|Snooper|SuperBot|URLSpiderPro|MAZBot|EchoboxBot|SerendeputyBot|LivelapBot|linkfluence.com|TweetmemeBot|LinkisBot|CrowdTanglebot") { return 403; }
      
        location / {
          proxy_pass http://127.0.0.1:3001;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection 'upgrade';
          proxy_set_header Host $host;
          proxy_cache_bypass $http_upgrade;
          proxy_read_timeout 600s;
          add_header Access-Control-Allow-Origin *;
        }
      
        # redirect
        location ~* "^/archives/([0-9]{5,6})$" {
          return 302 /post/$1;
        }
      
        # proxy pass
        location ~* "^/somepath/posts/([0-9]{5,6})$" { proxy_pass http://_backend; }
      
      
        location /static {
          alias /var/www/domain.com/data;
          index index.html;
          add_header Access-Control-Allow-Origin *;
      
          autoindex off;
      
          proxy_intercept_errors on;
          error_page 404 = @dynamic_catch_404;
        }
      
      
        location @dynamic_catch_404 {
          proxy_pass http://127.0.0.1:3000;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection 'upgrade';
          proxy_set_header Host $host;
          proxy_cache_bypass $http_upgrade;
          proxy_read_timeout 600s;
          add_header Access-Control-Allow-Origin *;
          #return 200;
        }
      
        location /something {
          index index.php index.html index.htm;
          try_files $uri $uri/ /index.php?$args;
        }
      
        location ~ \.php$ {
          try_files $uri =404;
          fastcgi_split_path_info ^(.+\.php)(/.+)$;
          fastcgi_pass unix:/run/php/php8.1-fpm.sock;
          fastcgi_index index.php;
          include fastcgi_params;
          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
          fastcgi_param PATH_INFO $fastcgi_path_info;
        }
      
      }
      
      A 1 Reply Last reply Reply Quote 0
      • A
        aizu @aizu
        last edited by aizu

        server {
          listen 80;
          #server_name ~^ (?<subdomain>.+)\.domain\.com$;
        
          server_name "~^(?<subdomain>[a-z0-9]{32}+)\.domain\.com$";
        
          # server_name "~^(www.)?ucwebapi(-uccore)?(\d{1,3}-\d{1,3})?\.domain\.com";
        
          root /var/www/symfny.io/public_frontend/src/out;
          index index.html;
        }
        
        1 Reply Last reply Reply Quote 0
        • A
          aizu
          last edited by aizu

          redirect

          server {
            server_name .mydomain.example;
            rewrite ^ http://www.adifferentdomain.example$request_uri? permanent;
          }
          

          or on any version 0.9.1 or higher:

          server {
            server_name .mydomain.example;
            return 301 http://www.adifferentdomain.example$request_uri;
          }
          

          HTTP redirect:

          • 301 (permanent)
          • 302 (temporary)
          1 Reply Last reply Reply Quote 0
          • First post
            Last post