【问题标题】:Multiple PHP based server blocks in nginx - 404 Errornginx 中的多个基于 PHP 的服务器块 - 404 错误
【发布时间】:2017-02-03 04:02:10
【问题描述】:

我是 Nginx 的新手,但遇到了问题。我有两个 wordpress 网站,我想在 Centos Linux 上使用 Nginx 启动它们。我所做的是:

  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 错误。

【问题讨论】:

  • 您最好在Server Fault 上提问。但不要交叉发布。
  • NGINX 访问日志有哪些内容?
  • 它只是显示我尝试查看我的网站

标签: php nginx centos7


【解决方案1】:

您的 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 了解更多信息。

【讨论】:

    【解决方案2】:

    您需要解决冗余

    mydomain1.com.conf

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

    myworkingfile.conf

    server {
        listen      80;
        server_name  crm.coderic.net;
        root /var/www/atrk/crm.atrk.com.co/public;
        index index.php;
        location / {
            try_files $uri $uri/ =404;
        }
        location ~ \.php$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-02-09
      • 2013-02-21
      • 1970-01-01
      • 1970-01-01
      • 2020-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多