2015-10-15 30 views
1

我遇到以下问题:的Prestashop,Nginx的和重定向

我们有两个的Prestashop 1.6网站(如bar.com和bar.foo.com)下的Nginx + PHP-FPM运行。两者在同一个VPS上,具有相同IP的域。

我的bar.foo.com店将我重定向到bar.com,尽管有不同的数据库,商店网址等。实际上,我们有其他页面,它们被重定向到同一个bar.com,并且它们都是子域foo.com。值得一提的是,foo.com运行平稳。

没有日志错误。

下面这些网站的配置,以及作为Nginx的conf文件。

bar.foo.com

server { 
     listen 80; 
     server_name bar.foo.com; 
     root /var/www/bar.foo.com/public_html; 

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

     index index.php index.html; 

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

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

     # Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac). 
     location ~ /\. { 
       deny all; 
       access_log off; 
       log_not_found off; 
     } 

     rewrite ^/api/?(.*)$ /webservice/dispatcher.php?url=$1 last; 
     rewrite ^/([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$1$2$3.jpg last; 
     rewrite ^/([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$1$2$3$4.jpg last; 
     rewrite ^/([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$1$2$3$4$5.jpg last; 
     rewrite ^/([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$1$2$3$4$5$6.jpg last; 
     rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$1$2$3$4$5$6$7.jpg last; 
     rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7$8.jpg last; 
     rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$7/$1$2$3$4$5$6$7$8$9.jpg last; 
     rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9$10.jpg last; 
     rewrite ^/c/([0-9]+)(\-[\.*_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$ /img/c/$1$2$3.jpg last; 
     rewrite ^/c/([a-zA-Z_-]+)(-[0-9]+)?/.+\.jpg$ /img/c/$1$2.jpg last; 
     rewrite ^/images_ie/?([^/]+)\.(jpe?g|png|gif)$ /js/jquery/plugins/fancybox/images/$1.$2 last; 
     try_files $uri $uri/ /index.php$is_args$args; 
     error_page 404 /index.php?controller=404; 

     location ~* \.(gif)$ { 
      expires 2592000s; 
     } 
     location ~* \.(jpeg|jpg)$ { 
      expires 2592000s; 
     } 
     location ~* \.(png)$ { 
      expires 2592000s; 
     } 
     location ~* \.(css)$ { 
      expires 604800s; 
     } 
     location ~* \.(js|jsonp)$ { 
      expires 604800s; 
     } 
     location ~* \.(js)$ { 
      expires 604800s; 
     } 
     location ~* \.(ico)$ { 
      expires 31536000s; 
     } 

     location ~ \.php$ { 
       try_files $uri =404; 
       include /etc/nginx/fastcgi_params; 
       fastcgi_pass unix:/var/run/php5-fpm.sock; 
       fastcgi_index index.php; 
       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
       fastcgi_intercept_errors on; 
     } 
} 

bar.com配置

server { 

     listen bar.com:80; 
     server_name *.bar.com; 
     root /var/www/bar.com/public_html; 

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

     index index.php index.html; 

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

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

     # Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac). 
     location ~ /\. { 
       deny all; 
       access_log off; 
       log_not_found off; 
     } 

     rewrite ^/api/?(.*)$ /webservice/dispatcher.php?url=$1 last; 
     rewrite ^/([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$1$2$3.jpg last; 
     rewrite ^/([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$1$2$3$4.jpg last; 
     rewrite ^/([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$1$2$3$4$5.jpg last; 
     rewrite ^/([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$1$2$3$4$5$6.jpg last; 
     rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$1$2$3$4$5$6$7.jpg last; 
     rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7$8.jpg last; 
     rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$7/$1$2$3$4$5$6$7$8$9.jpg last; 
     rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9$10.jpg last; 
     rewrite ^/c/([0-9]+)(\-[\.*_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$ /img/c/$1$2$3.jpg last; 
     rewrite ^/c/([a-zA-Z_-]+)(-[0-9]+)?/.+\.jpg$ /img/c/$1$2.jpg last; 
     rewrite ^/images_ie/?([^/]+)\.(jpe?g|png|gif)$ /js/jquery/plugins/fancybox/images/$1.$2 last; 
     try_files $uri $uri/ /index.php$is_args$args; 
     error_page 404 /index.php?controller=404; 

     location ~* \.(gif)$ { 
      expires 2592000s; 
     } 
     location ~* \.(jpeg|jpg)$ { 
      expires 2592000s; 
     } 
     location ~* \.(png)$ { 
      expires 2592000s; 
     } 
     location ~* \.(css)$ { 
      expires 604800s; 
     } 
     location ~* \.(js|jsonp)$ { 
      expires 604800s; 
     } 
     location ~* \.(js)$ { 
      expires 604800s; 
     } 
     location ~* \.(ico)$ { 
      expires 31536000s; 
     } 

     location ~ \.php$ { 
       try_files $uri =404; 
       include /etc/nginx/fastcgi_params; 
       fastcgi_pass unix:/var/run/php5-fpm.sock; 
       fastcgi_index index.php; 
       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
       fastcgi_intercept_errors on; 
     fastcgi_read_timeout 300; 
     } 
} 

nginx.conf

user www-data; 
worker_processes 4; 
pid /var/run/nginx.pid; 

events { 
    worker_connections 768; 
    # multi_accept on; 
} 

http { 

    ## 
    # Basic Settings 
    ## 

    sendfile on; 
    tcp_nopush on; 
    tcp_nodelay on; 
    keepalive_timeout 65; 
    types_hash_max_size 2048; 
    # server_tokens off; 

    # server_names_hash_bucket_size 64; 
    # server_name_in_redirect off; 

    include /etc/nginx/mime.types; 
    default_type application/octet-stream; 

    ## 
    # Logging Settings 
    ## 

    #rewrite_log on; 

    access_log /var/log/nginx/access.log; 
    #error_log /var/log/nginx/error.log notice; 
    error_log /var/log/nginx/error.log; 
    #error_log /var/log/nginx/error.log debug; 


    ## 
    # Gzip Settings 
    ## 

    gzip on; 
    gzip_disable "msie6"; 

    # gzip_vary on; 
    # gzip_proxied any; 
    # gzip_comp_level 6; 
    # gzip_buffers 16 8k; 
    # gzip_http_version 1.1; 
    # gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript; 

    ## 
    # nginx-naxsi config 
    ## 
    # Uncomment it if you installed nginx-naxsi 
    ## 

    #include /etc/nginx/naxsi_core.rules; 

    ## 
    # nginx-passenger config 
    ## 
    # Uncomment it if you installed nginx-passenger 
    ## 

    #passenger_root /usr; 
    #passenger_ruby /usr/bin/ruby; 

    ## 
    # Virtual Host Configs 
    ## 


    fastcgi_buffers 16 16k; 
    fastcgi_buffer_size 32k; 

    include /etc/nginx/conf.d/*.conf; 
    include /etc/nginx/sites-enabled/*; 
} 

我将不胜感激任何想法如何解决这个问题。

+0

你确定重定向在Nginx端吗?当你有像/var/www/(foo.)bar.com/public_html这样的空文件夹时发生了什么,它仍然被重定向? –

+0

是的。我这次从bar.com重定向到foo.bar.com – user4689565

回答

0

所以,没有什么有关的Prestashop(只是通知一下标题)和 来解决这个问题,在bar.com的conf使用listen 80;,所以会出现:

server { listen 80; server_name .bar.com; root /var/www/bar.com/public_html;

而且这个页面可能有帮助:http://nginx.org/en/docs/http/server_names.html

+0

似乎它实际上是一个Prestashop(主题?)问题。相同的设置 - 两种不同的Web服务(一个是虚拟的,另一个是Prestashop的),配置可以在虚拟页面上正常工作,但第二个Web服务从foo.bar.com重定向到bar.com。 – user4689565

+0

我刚刚向你展示了你的Nginx配置是错误的,正是这行'listen bar.com:80;',你可以在这里找到类似的Q/A。 http://stackoverflow.com/questions/11773544/nginx-different-domains-on-same-ip –