nginx 常用的配置

yii

    server {
        listen 80;
        server_name web.xcx.cn;
        root /work/admin;

        index index.html index.htm index.php;

        location / {
            try_files $uri $uri/ /index.php$is_args$args;
        }

         location /admin {
          alias  /work/admin/backend/web;
          rewrite  ^(/admin)/$ $1 permanent;
          try_files  $uri /backend/web/index.php?$args;
        }

        location ~ ^/admin/(.+\.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar))$ {
          access_log  off;
          expires  360d;

          rewrite  ^/admin/(.+)$ /backend/web/$1 break;
          rewrite  ^/admin/(.+)/(.+)$ /backend/web/$1/$2 break;
          try_files  $uri =404;
        }

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

websocket

  3 server {
  2     listen  80;
  1     server_name  web.socket.cn;
4       root  /work/websock;
  1
location /socket {
           proxy_pass http://127.0.0.1:9501;
           # WebScoket Support
           proxy_read_timeout 1800;
           proxy_http_version 1.1;
           proxy_set_header Upgrade $http_upgrade;
           proxy_set_header Connection "upgrade";
  
           proxy_set_header Origin xxx;
          proxy_set_header X-Real-IP $remote_addr;
         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header Host $http_host;
         proxy_set_header X-NginX-Proxy true;
     }
 15
 16     location / {
 17         try_files $uri $uri/ /index.php$is_args$args;
 18     }
 19
 20     location ~ \.php$ {
 21         try_files $uri =404;
 22         fastcgi_pass 127.0.0.1:9000;
 23         fastcgi_index  index.php;
 24         fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
 25         include fastcgi_params;
 26     }
 27
 28 }

thinkphp

    server {
       listen 80;
       server_name web.fadmin.cn;
       root /work/fadmin/public;
       index index.html index.htm index.php;

       location / {
           if (!-e $request_filename) {
               rewrite  ^(.*)$  /index.php?s=/$1  last;
               break;
           }
       }
       location ~ \.php$ {
           try_files $uri =404;
           fastcgi_pass 127.0.0.1:9000;
           fastcgi_index  index.php;
           fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
           include fastcgi_params;
       }
   }

nginx 代理访问解决跨越

location /README.md {
    proxy_set_header  X-Real-IP  $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_pass https://github.com/moonbingbing/openresty-best-practices/blob/master/README.md;
}

    set $origin 'http://web.xcx.cn';
    add_header 'Access-Control-Allow-Origin' $origin;
    add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
    add_header 'Access-Control-Max-Age' 1728000;
    add_header 'Content-Type' 'text/plain charset=UTF-8';
    add_header 'Content-Length' 0;

猜你喜欢

转载自www.cnblogs.com/zhsngq/p/11696410.html