nginx rewriting with drupal windows(使用drupal windows重写nginx)
问题描述
这是我第一次使用 nginx ,我有两个问题,第一个是我想自动重定向 http://localhost/project 到 http://localhot/project/en/ 并且 en 是项目的子目录.
第二个问题:在 localhost/project/en/我可以看到 index.php 我的意思是主页,但是从项目中的每次重定向都会给我 404 not found like localhost/project/en/people/或localhost/project/en/people/article1
注意:我在带有 drupal 和 .这是我的配置:
worker_processes 1;事件{worker_connections 1024;}http {server_tokens 开启;发送文件;tcp_nopush 开启;tcp_nodelay 开启;关闭;#超时client_body_timeout 5;client_header_timeout 5;keepalive_timeout 25 25;send_timeout 15s;resolver_timeout 3s;#Directive 设置与 FastCGI 服务器连接的超时时间.需要注意的是,这个值不能超过 75 秒.fastcgi_connect_timeout 5s;#Directive 设置上游等待 fastcgi 进程发送数据的时间量.如果您长时间运行 fastcgi 进程,这些进程在完成处理之前不会产生输出,请更改此指令.如果您在错误日志中看到上游超时错误,则将此参数增加到更合适的值.fastcgi_read_timeout 400s;#Directive 指定对服务器的请求超时.超时是在两次写入操作之间计算的,而不是针对整个请求.如果在此期间没有写入数据,则服务关闭连接.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 关闭;#php 最大上传限制不能大于这个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;包括 nginx.mimetypes.conf;default_type 文本/html;### 日志设置##access_log "c:/wt-nmp/log/nginx_access.log";error_log "c:/wt-nmp/log/nginx_error.log" 警告;#debug 或警告log_not_found on;#enables 或禁用 error_log 中有关在磁盘上找不到文件的消息.rewrite_log 关闭;#别管这个fastcgi_intercept_errors 关闭;gzip 关闭;索引 index.php index.htm index.html;服务器 {听 127.0.0.1:80 default_server;#listen [::1]:80 ipv6only=on;server_name 本地主机;根c:/wt-nmp/www/";自动索引开启;允许 127.0.0.1;#允许 ::1;全部否认;# 拒绝访问 .htaccess 文件,如果 Apache 的文档根目录# 同意 nginx 的观点#位置 ~/.ht {#全部拒绝;}位置/项目{索引 index.php;try_files $uri $uri/@handler;}位置@handler { 重写//project/en/index.php;}位置 ~ ^/en/{根c:/wt-nmp/www/project";try_files $uri $uri//en/index.php?$args;}#tools 现在由 wt-nmp/include/tools/提供位置 ~ ^/tools/.*.php$ {根c:/wt-nmp/include";try_files $uri =404;包括 nginx.fastcgi.conf;fastcgi_pass php_farm;}位置〜^/工具/{根c:/wt-nmp/include";}位置 ~ .php$ {# try_files $uri =404;# fastcgi_pass php_farm;fastcgi_pass 127.0.0.1:9000;包括 nginx.fastcgi.conf;}}包括domains.d/*.conf;包括 nginx.phpfarm.conf;}
WPN-XM 服务器堆栈Drupal 7 安装说明使用干净的 URL"
安装步骤:
- 下载 http://ftp.drupal.org/files/projects/drupal-7.34.zip
- 解压到 c:wpn-xmwww
- 将版本化文件夹重命名为drupal" = drupal 的完整路径 = c:wpn-xmwwwdrupal
- 运行drupal安装 - http://localhost/drupal/install.php
- 激活缺少的 PHP 扩展:可能是 gd2、mbstring,然后重启 php
- 重新加载安装页面,全部为绿色,进入数据库对话框
- 在填写数据库对话框之前,在 adminer 中创建数据库drupal",然后在对话框中将其用作 db
- 继续安装步骤,直到完成
浏览:http://localhost/drupal/好的,你刚刚在 localhost 上安装了 Drupal.
<小时>URL 重写和清理 URL 步骤:
安装后,要让短 URL 正常工作,需要做 3 件事:
- 提供新主机http://drupal.dev"
- 添加一个用于 URL 重写的 Nginx 配置
- 在 Drupal 配置中启用Clean URLs"
<块引用>
重要提示
short/nice/clean URL 仅适用于以"http://drupal.dev/" 不适用于 "localhost".使用扩音器:不工作使用 "http://localhost/..." - 使用 "http://drupal.dev/...".
<小时>
- 将drupal.dev"添加到主机文件
您需要将drupal.dev"添加到您的hosts"文件中.
- 手动或
- 通过 WPN-XM 服务器控制面板 - 步骤:
- 右键单击托盘图标 - 管理主机"
- 添加" - 数据127.0.01"drupal.dev"
- 点击确定.
- Windows 权限对话框弹出.
- 单击确定"以允许写入主机"文件.
- 如果防病毒工具阻止写入 hosts 文件,请禁用 AV,重复上述步骤,然后再次启用.
检查:http://drupal.dev/?q=admin - 好的
-
- **为 Drupal7 添加一个 Nginx 服务器块 **
使用以下 Nginx 配置文件来激活重写 URL:
https://github.com/WPN-XM/software/blob/master/nginx/config/conf/domains-disabled/drupal7.conf
您可以在主 nginx.conf
中使用 include
指令来加载它.
重新启动或重新哈希 Nginx 以激活新配置.
您现在可以开始在浏览器中使用网址http://drupal.dev".
<块引用>重要的是您的服务器块中的以下指令
# 使站点可从 http://drupal.dev/访问server_name drupal.dev;
和重写规则rewrite ^/(.*)$/index.php?q=$1;
.
检查:http://drupal.dev/admin
<小时>在 Drupal 配置中激活Clean URLs"
- 测试干净的网址"
- http://drupal.dev/admin/config/search/clean-网址/检查
- 响应:
{"status":true}
- 响应:
- http://drupal.dev/admin/config/search/clean-网址/检查
- 启用干净的网址"(b)
- http://drupal.dev/admin/config/search/clean-urls一>
- 选中复选框 &保存.
- http://drupal.dev/admin/config/search/clean-urls一>
- 测试干净的网址"
菜单中的链接应以Clean URL"形式出现,不带?q=".
最终检查:
- 悬停菜单中的链接并检查短网址.- 好的
- http://drupal.dev/admin - 好的
- http://drupal.dev/user/login - 好的
完成.
this is the first time i use nginx , and i have two problems with it, the first one is that i want to redirect http://localhost/project automatically to http://localhot/project/en/ and en is subdirectory on project.
The second problem : in localhost/project/en/ i can see the index.php i mean the main page but every redirecting from the project give me 404 not found like localhost/project/en/people/ or localhost/project/en/people/article1
NB : i use nginx in windows with drupal and . here is my configuration:
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;
}
WPN-XM Server Stack Installation Instructions for Drupal 7 with "Clean URLs"
Installation Steps:
- Download http://ftp.drupal.org/files/projects/drupal-7.34.zip
- Extract into c:wpn-xmwww
- rename versionized folder to just "drupal" = full path to drupal = c:wpn-xmwwwdrupal
- run drupal install - http://localhost/drupal/install.php
- activate missing PHP extensions: maybe gd2, mbstring, then restart php
- reload install page, all green, proceed to database dialog
- before filling the database dialog, create database "drupal" in adminer, then use that as db in dialog
- proceed with install steps until done
Browse: http://localhost/drupal/ Ok, you just installed Drupal on localhost.
URL Rewriting and Clean URLs Steps:
After the installation, 3 things are needed to get short URLs working:
- provide new host "http://drupal.dev"
- add a Nginx Configuration for URL rewriting
- enabling "Clean URLs" in the Drupal Configuration
Important Notice
The short/nice/clean URLs work only for URLs starting with "http://drupal.dev/" not for "localhost". Using megaphone: not working with "http://localhost/..." - use "http://drupal.dev/...".
- Add "drupal.dev" to hosts file
You need to add "drupal.dev" to your "hosts" file.
- manually or
- via the WPN-XM Server Control Panel - Steps:
- right-click tray icon - "Manage Hosts"
- "Add" - Data "127.0.01" "drupal.dev"
- Click Ok.
- The Windows Permissions Dialog pops up.
- Click Ok, to allow writing to the "hosts" file.
- If Anti-Virus tool blocks writing to the hosts file, disable AV it, repeat the steps, enable it again.
Check: http://drupal.dev/?q=admin - ok
-
- **Add a Nginx server block for Drupal7 **
Use the following Nginx config file to activate rewriting URLs:
https://github.com/WPN-XM/software/blob/master/nginx/config/conf/domains-disabled/drupal7.conf
You might use an include
directive in your main nginx.conf
to load it.
Restart or rehash Nginx to activate the new configuration.
You can now start using the URL "http://drupal.dev" in your browser.
Important is the the following directive in your server block
# Make site accessible from http://drupal.dev/ server_name drupal.dev;
and the rewrite rule
rewrite ^/(.*)$ /index.php?q=$1;
.
Check: http://drupal.dev/admin
Activate "Clean URLs" in Drupal Configuration
- Testing "Clean URLs"
- http://drupal.dev/admin/config/search/clean-urls/check
- Response:
{"status":true}
- Response:
- http://drupal.dev/admin/config/search/clean-urls/check
- Enabling "Clean URLs" (b)
- http://drupal.dev/admin/config/search/clean-urls
- Check Checkbox & Save.
- http://drupal.dev/admin/config/search/clean-urls
- Testing "Clean URLs"
Links in the menu should appear in "Clean URL" form without "?q=".
Final Checks:
- Hover links in the menu and check for short URLs. - ok
- http://drupal.dev/admin - ok
- http://drupal.dev/user/login - ok
Done.
这篇关于使用drupal windows重写nginx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用drupal windows重写nginx
基础教程推荐
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- 在多维数组中查找最大值 2021-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01