English 中文(简体)
供通过子午线在原食服务器上使用的网站打字
原标题:Config for serving website on nginx server via sub url
  • 时间:2012-04-25 16:46:00
  •  标签:
  • nginx
  • vhosts

we have two nginx servers. The first server receives a request via www.example.com/partner. He sends the whole request to the second server which has php+fastCgi configured. Nginx access log from second server:

“GET /partner/HTTP/1.0” 200 284

在第二台服务器上,我有一个这样的幽灵:

server {
       listen my.ip:80;
       server_name www.example.com;
       root /var/www/example;

       if ($http_host != "www.example.com") {
                 rewrite ^ http://www.example.com$request_uri permanent;
       }

       index index.php index.html;


       location = /partner/favicon.ico {
                log_not_found off;
                access_log off;
                expires max;
       }


        location @nocache {
                try_files $uri $uri/ /index.php?$args;
       }
       location = /partner/robots.txt {
                allow all;
                log_not_found off;
                access_log off;
       }

       location ^~ /partner/typo3temp/tx_ncstaticfilecache {
                expires 43200;
                charset utf-8;
       }

       location = /partner/clear.gif {
                empty_gif;
                expires max;
       }
       location ^~ /partner/typo3/gfx {
                expires max;
       }
       location ^~ /partner/typo3temp/compressor {
                expires max;
       }   

    location /partner {    


                if ($query_string ~ ".+") {
                        return 405;
                }
                # pass requests from logged-in users to PHP
                if ($http_cookie =  nc_staticfilecache|be_typo_user  ) {
                        return 405;
                } # pass POST requests to PHP
                if ($request_method !~ ^(GET|HEAD)$ ) {
                        return 405;
                }
                if ($http_pragma =  no-cache ) {
                        return 405;
                }
                if ($http_cache_control =  no-cache ) {
                        return 405;
                }
                error_page 405 = @nocache;

                # serve requested content from the cache if available, otherwise pass the request to PHP
                try_files /typo3temp/tx_ncstaticfilecache/$host${request_uri}index.html @nocache;


       location ~* .(sql|htaccess|htpasswd|tpl|html5|xhtml) {
                deny all;
       }

       location ~*  .(jpg|jpeg|png|gif|css|js|ico)$ {
                expires max;
                log_not_found off;
       }

       location ~* .(cur|ico|gif|png|jpe?g|css|js|swf|woff)((?dddddddddd)|(?s=dddddddddd))$ {
                expires max;
                log_not_found off;
       }
       location ~* .(cur|ico|gif|png|jpe?g|css|js|swf|woff)(?vdd?.dd?.dd?)$ {
                expires max;
                log_not_found off;
       }
       location ~* ^(/typo3/sysext|/typo3conf/ext).*.(cur|ico|gif|png|jpe?g|css|js|swf|woff) {
                expires max;
                log_not_found off;
       }



       location ~ /. {
                deny all;
                access_log off;
                log_not_found off;
       }

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

我得到的问题和403个错误。 任何错误的想法?

最佳回答

之所以能够下载Sphp的档案,很可能是因为在另一个地点区块下铺设的营地处理区块(假设已经正确设置了Sphp)。

总的来说,你们的争执似乎过于复杂,我确信,无论它正在做什么任务,都能够以一种更加直截了当的组合来完成。

我做了基本清理/合并工作,但没有全貌,有些轨道可能消失。 不过,应该给你一些想法。

尽管PHP正在将其从被封锁的地点撤出,但这一点很重要。

此外,利用《地位法》418,而不是405条重新定向,因为其他原因可以合法地产生405。

利用一个单独的服务器组,例如:com至www.example.com,为改进业绩而调整方向。

server {
    listen my.ip:80;
    server_name example.com;
    rewrite ^ http://www.example.com$request_uri? permanent;
}

server {
    listen my.ip:80;
    server_name www.example.com;
    root /var/www/example;
    index index.php index.html;
    error_page 418 = @nocache;

    if ($query_string ~ ".+") {
        return 418;
    }
    # pass requests from logged-in users to PHP
    if ($http_cookie =  nc_staticfilecache|be_typo_user  ) {
        return 418;
    } 
    # pass POST requests to PHP
    if ($request_method !~ ^(GET|HEAD)$ ) {
        return 418;
    }

    location = /partner/robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

    location ^~ /partner/typo3temp/tx_ncstaticfilecache {
        expires 43200;
        charset utf-8;
    }

    location = /partner/clear.gif {
        empty_gif;
        expires max;
    }

    location ^~ /partner/typo3/gfx {
        expires max;
    }
    location ^~ /partner/typo3temp/compressor {
        expires max;
    }

    location /partner {
        # serve requested content from the cache if available, 
        # otherwise pass the request to PHP
        try_files /typo3temp/tx_ncstaticfilecache/$host${request_uri}index.html @nocache;
    }

    location ~* .(sql|tpl|html5|xhtml) {
        deny all;
    }

    location ~*  .(jpg|jpeg|png|gif|css|js|ico)(.*)$ {
        expires max;
        log_not_found off;
    }

    location ~ /. {
        deny all;
        access_log off;
        log_not_found off;
    }

    location ~ .php$ {
        return 418;
    }

    location @nocache {
        try_files $uri =404;
        include /etc/nginx/fastcgi_params;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_index index.php;            
    }
}
问题回答

暂无回答




相关问题
nginx behaved differently for different version

I have used docker image nginx:1.18.0-alpine previously and below is the conf. It works as expected app.localhost --> points to the block wit server_name app.* localhost --> points to the other ...

What s limiting my PHP resources?

I m having a problem getting more memory out of PHP. This is the error message: Fatal error: Allowed memory size of 20971520 bytes exhausted (tried to allocate 82 bytes) in ... Yet: I ve set ...

what user I should run my nginx or php-fpm processes

Ok. Im little bit confused about those permissions in linux so please people help me out. The trouble is that I dont want to run server as root, so I created another user with sudo privileges so he ...

Nginx 301 redirect inc. set cookie

what I m looking for is the ability for nginx to detect that a url has the query string variable cid. for example www.adomain.com/froggy?cid=12&as=false (query string can be solo or mixed with ...

Nginx raises 404 when using format => js

I upload images to my App using Ajax and an Iframe. In Development everything works like a charm. But in production Nginx suddenly raises a 404 error. When I look into the log, the request never hits ...

nginx errors readv() and recv() failed

I use nginx along with fastcgi. I see a lot of the following errors in the error logs readv() failed (104: Connection reset by peer) while reading upstream and recv() failed (104: Connection ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

热门标签