2017-02-03 43 views
1

我在Nginx中很新,我對它有問題。我有兩個wordpress網站,我想在Centos Linux上用Nginx啓動它們。我所做的是:nginx中多個基於PHP的服務器模塊 - 404錯誤

  1. 創建網站,提供和網站使用,在/ etc/nginx的/
  2. 把我的網站的配置文件(.conf文件)到站點可用
  3. 我創建符號鏈接他們使用ln -s

我的配置文件如下: nginx.conf

http { 
    log_format main '$remote_addr - $remote_user [$time_local] "$request" ' 
         '$status $body_bytes_sent "$http_referer" ' 
         '"$http_user_agent" "$http_x_forwarded_for"'; 

    access_log /var/log/nginx/access.log main; 

    sendfile   on; 
    tcp_nopush   on; 
    tcp_nodelay   on; 
    keepalive_timeout 65; 
    types_hash_max_size 2048; 

    default_type  application/octet-stream; 

    # Load modular configuration files from the /etc/nginx/conf.d directory. 
    # See http://nginx.org/en/docs/ngx_core_module.html#include 
    # for more information. 
    # include /etc/nginx/conf.d/*.conf 
    server { 
     listen  80 default_server; 
     listen  [::]:80 default_server; 
     server_name _; 
     root   /usr/share/nginx/html; 
     index  index.html; 
     # Load configuration files for the default server block. 
     include /etc/nginx/default.d/*.conf; 

     location/{ 
     } 
    location ~ \.php$ { 
     try_files $uri =404; 
     fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; 
     fastcgi_index index.php; 
     include fastcgi_params; 
    } 

     error_page 404 /404.html; 
      location = /40x.html { 
     } 

     error_page 500 502 503 504 /50x.html; 
      location = /50x.html { 
     } 
    } 
include /etc/nginx/sites-enabled/*.conf; 
server_names_hash_bucket_size 64; 
} 

mydomain1.com.conf

server { 
    listen 80; 
    server_name mydomain1.com www.mydomain1.com; 
    location/{ 
     root /var/www/html/; 
     index index.php; 
    } 
    location ~ \.php$ { 
     try_files $uri =404; 
     fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; 
     fastcgi_index index.php; 
     include fastcgi_params; 
    } 

} 

mydomain2.com.conf

server { 
    listen 80; 
    server_name mydomain2.com www.mydomain2.com; 
    location/{ 
     try_files $uri $uri/ =404; 
     root /var/www/aramis; 
     index index.php; 
    } 
    location ~ \.php$ { 
     try_files $uri =404; 
     fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; 
     fastcgi_index index.php; 
     include fastcgi_params; 
    } 

} 

/etc/php-fm.d/www.conf

[www] 
listen = /var/run/php-fpm/php-fpm.sock 
listen.allowed_clients = 127.0.0.1 
listen.owner = nobody 
listen.group = nobody 
;listen.mode = 0660 
user = nginx 
group = nginx 
pm = dynamic 
pm.max_children = 50 
pm.start_servers = 5 
pm.min_spare_servers = 5 
pm.max_spare_servers = 35 
php_admin_value[error_log] = /var/log/php-fpm/www-error.log 
php_admin_flag[log_errors] = on 
php_value[session.save_handler] = files 
php_value[session.save_path] = /var/lib/php/session 

我也試過找到php-fpm.sock,但我沒有成功。 當我嘗試從瀏覽器中看到我的網站時,我得到的是404錯誤。

+0

你最好過問[sf]。但不要交叉郵遞。 – miken32

+0

NGINX訪問日誌有什麼? –

+0

它只是顯示我試圖看到我的網站 – Mahdi

回答

0

您的PHP位置塊沒有root指令。如果它對於所有文件(靜態和動態)都是相同的根,則將root指令移動到server塊,並允許location兩個塊繼承相同的值。

server { 
    ... 
    root /var/www/aramis; 
    index index.php; 

    location/{ 
     try_files $uri $uri/ =404; 
    } 
    location ~ \.php$ { 
     try_files $uri =404; 
     ... 
    } 
} 

查看this document瞭解更多。