2015-10-15 25 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 –