1

这是我第一次使用 nginx ,我有两个问题,第一个是我想将http://localhost/project 自动重定向到http://localhot/project/en/ 并且 en 是子目录项目。

第二个问题:在 localhost/project/en/ 我可以看到 index.php 我的意思是主页,但是从项目中进行的每次重定向都会给我 404 not found 像 localhost/project/en/people/ 或 localhost/project/en/人/文章1

注意:我在 windows 中使用带有 drupal 和 . 这是我的配置:

    worker_processes  1;
events {
    worker_connections  1024;
}
http {
    server_tokens       on;
    sendfile        on;
    tcp_nopush      on;
    tcp_nodelay     on;
    ssi         off;

    #Timeouts
        client_body_timeout 5;
        client_header_timeout   5;
        keepalive_timeout   25 25;
        send_timeout        15s;
    resolver_timeout    3s;

    #Directive sets timeout period for connection with FastCGI-server. It should be noted that this value can't exceed 75 seconds. 
    fastcgi_connect_timeout 5s;

    #Directive sets the amount of time for upstream to wait for a fastcgi process to send data. Change this directive if you have long running fastcgi processes that do not produce output until they have finished processing. If you are seeing an upstream timed out error in the error log, then increase this parameter to something more appropriate. 
    fastcgi_read_timeout    400s;

    #Directive specifies request timeout to the server. The timeout is calculated between two write operations, not for the whole request. If no data have been written during this period then serve closes the connection.
    fastcgi_send_timeout    150s;

    fastcgi_buffers 8 32k;
    fastcgi_buffer_size 32k;
    #fastcgi_busy_buffers_size 256k;
    #fastcgi_temp_file_write_size 256k;

    open_file_cache off;

    #php max upload limit cannot be larger than this       
    client_max_body_size 8m;
        ####client_body_buffer_size  1K;
        client_header_buffer_size 1k;
        large_client_header_buffers 2 1k;   
    types_hash_max_size 2048;

    include nginx.mimetypes.conf;
    default_type text/html;

    ##
    # Logging Settings
    ##
    access_log "c:/wt-nmp/log/nginx_access.log";
    error_log "c:/wt-nmp/log/nginx_error.log" warn; #debug or warn
    log_not_found on;  #enables or disables messages in error_log about files not found on disk. 
    rewrite_log off;

    #Leave this off
    fastcgi_intercept_errors off;

    gzip  off;

    index  index.php index.htm index.html;

    server {
        listen      127.0.0.1:80    default_server;
        #listen     [::1]:80    ipv6only=on;
        server_name  localhost;

        root "c:/wt-nmp/www/";
        autoindex on;

        allow       127.0.0.1;
        #allow      ::1;
        deny        all;

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        location ~ /\.ht {
           # deny  all;   
        }

    location /project {
    index index.php;
    try_files $uri $uri/ @handler;
    }

    location @handler { rewrite / /project/en/index.php; }

    location ~ ^/en/ {
         root "c:/wt-nmp/www/project";
        try_files $uri $uri/ /en/index.php?$args;
    }
        #tools are now served from wt-nmp/include/tools/
        location ~ ^/tools/.*\.php$ {                   
            root "c:/wt-nmp/include";
            try_files $uri =404; 
            include     nginx.fastcgi.conf;
            fastcgi_pass    php_farm;
        }
        location ~ ^/tools/ {
            root "c:/wt-nmp/include";
        }

        location ~ \.php$ {
           # try_files $uri =404; 
               # fastcgi_pass   php_farm;
            fastcgi_pass     127.0.0.1:9000;
            include     nginx.fastcgi.conf;
            }

    }

    include domains.d/*.conf;

    include nginx.phpfarm.conf;
}
4

1 回答 1

0

Drupal 7 的 WPN-XM 服务器堆栈安装说明,带有“干净的 URL”

安装步骤:

  1. 下载http://ftp.drupal.org/files/projects/drupal-7.34.zip
  2. 解压到 c:\wpn-xm\www
  3. 将版本化文件夹重命名为 "drupal" = drupal 的完整路径 = c:\wpn-xm\www\drupal
  4. 运行 drupal 安装 - http://localhost/drupal/install.php
  5. 激活缺少的 PHP 扩展:可能是 gd2、mbstring,然后重新启动 php
  6. 重新加载安装页面,全部为绿色,进入数据库对话框
  7. 在填写数据库对话框之前,在管理员中创建数据库“drupal”,然后在对话框中将其用作数据库
  8. 继续安装步骤,直到完成

浏览:http://localhost/drupal/ 好的,你刚刚在 localhost 上安装了 Drupal。


URL 重写和清理 URL 步骤:

安装后,需要做 3 件事才能使短 URL 正常工作:

  1. 提供新主机“ http://drupal.dev
  2. 添加用于 URL 重写的 Nginx 配置
  3. 在 Drupal 配置中启用“Clean URLs”

重要通知

short/nice/clean URL 仅适用于以“ http://drupal.dev/ ”开头的 URL,不适用于“localhost”。使用扩音器:不使用“ http://localhost/ ...” - 使用“ http://drupal.dev/ ...”。


  1. 将“drupal.dev”添加到主机文件

您需要将“drupal.dev”添加到您的“hosts”文件中。

  • 手动或
  • 通过 WPN-XM 服务器控制面板 - 步骤:
    • 右键单击托盘图标 - “管理主机”
    • “添加” - 数据“127.0.01”“drupal.dev”
    • 单击确定。
    • 弹出 Windows 权限对话框。
    • 单击确定,以允许写入“主机”文件。
    • 如果防病毒工具阻止写入主机文件,请禁用 AV,重复这些步骤,再次启用它。

检查:http ://drupal.dev/?q=admin - 好的

-

  1. **为 Drupal7 添加一个 Nginx 服务器块 **

使用以下 Nginx 配置文件来激活重写 URL:

https://github.com/WPN-XM/software/blob/master/nginx/config/conf/domains-disabled/drupal7.conf

您可以在 main 中使用include指令nginx.conf来加载它。

重新启动或重新哈希 Nginx 以激活新配置。

您现在可以开始在浏览器中使用 URL“ http://drupal.dev ”。

重要的是您的服务器块中的以下指令

# Make site accessible from http://drupal.dev/
server_name drupal.dev;

和重写规则rewrite ^/(.*)$ /index.php?q=$1;

检查:http ://drupal.dev/admin


  1. 在 Drupal 配置中激活“清理 URL”

菜单中的链接应以不带“?q=”的“Clean URL”形式出现。

最终检查:

完毕。

于 2015-02-14T19:56:22.507 回答