2015-03-03 94 views
0
我有Tomcat上運行一個網站

安裝WordPress,我想設置我的博客同一個網站的子目錄下的example.com/blog在子目錄中的Nginx

我使用多種設置它嘗試過,但沒有工作中。有的給出502錯誤,有的給404以下配置給出沒有指定輸入文件錯誤。

server { 
    listen 80; 
    server_name www.example.com; 
    gzip on; 

    location/{ 
     proxy_set_header X-Forwarded-Host $host; 
     proxy_set_header X-Forwarded-Server $host; 
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
     proxy_set_header X-Real-Ip $remote_addr; 
     proxy_pass http://localhost:8080; 
    } 

    location ^~ /blog{ 
     root /home/myubuntu/www/blog; 
     index index.php index.html index.htm; 
     try_files $uri $uri/ /blog/index.php?q=$uri&$args; 

     fastcgi_split_path_info ^(.+\.php)(/.+)$; 
     fastcgi_pass unix:/var/run/php5-fpm.sock; 
     fastcgi_index index.php; 
     include fastcgi_params; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
    } 
} 

我運行一個子域此相同的博客與成功配置如下:

server { 
    listen 80; 
    root /home/myubuntu/www/blog; 
    index index.php index.html index.htm; 

    server_name blog.example.com; 
    gzip on; 

    location/{ 
     try_files $uri $uri/ /index.php?q=$uri&$args; 
    } 

    error_page 404 /404.html; 

    error_page 500 502 503 504 /50x.html; 
    location = /50x.html { 
     root /usr/share/nginx.html; 
    } 

    location ~ \.php$ { 
     try_files $uri =404; 
     fastcgi_split_path_info ^(.+\.php)(/.+)$; 
     fastcgi_pass unix:/var/run/php5-fpm.sock; 
     fastcgi_index index.php; 
     include fastcgi_params; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
    } 

}

可能有人請告訴我,我在做什麼錯

回答

0

我d同樣的問題,並經過兩天的搜索結合搜索設置和搜索...我做了一些適用於我的東西。 我nginx的運行1.8 WordPress的......說實話不知道...

這是我的配置

server { 
    listen 80; 
    server_name www.example.com example.com; 

    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; 

    location/{ 
      root  /http; 
      index  index.php index.html index.htm; 
      try_files $uri $uri/ @wordpress; 
    } 

    location ~ \.php$ { 
      root   /http/wordpress; 
      fastcgi_pass unix:/var/run/php5-fpm.sock; 
      fastcgi_index index.php; 
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
      include  fastcgi_params; 
    } 

    location @wordpress { 
      try_files $uri /index.php; 
      fastcgi_intercept_errors on; 
    } 

    location /wordpress { 
      try_files $uri $uri/ @wordpress; 
    } 

    error_page 404 /404.html; 
    error_page 500 502 503 504 /50x.html; 
    location = /50x.html { 
      root /usr/share/nginx/www; 
    } 
} 

我希望這有助於你...

0


這裏是設置路徑:

etc/nginx/sites-availability/default
您需要遵循nginx和wordpress中的最小設置。
server { 
     listen 80;

root /var/www/html; index index.php; server_name 182.71.214.253; location /blogs { try_files $uri $uri/ /blogs/index.php?$args; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /var/www/html; #root /usr/share/nginx/html; } # pass the PHP scripts to FastCGI server listening on the php-fpm socket location ~ \.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }} </code> </pre> After this settings,You need to restart the two services.<pre><code>1:NGINX : sudo service nginx restart<br/>2:php5-fpm : sudo service php5-fpm restart</code></pre><br/>After that your website is working fine.<br/>If still needs problem then share with us.
+0

任何人都可以管理這個代碼,即刪除HTML標籤('code'和pre)並以系統化的方式進行管理。因爲它是經過測試的代碼並且工作正常。 – Shankaranand 2015-07-03 11:41:37