404 - 从本地主机(apache)传输到 nginx 服务器后的其他永久链接
404 - Other permalink after transfer from localhost(apache) to nginx server
我已经将 Wordpress 站点从本地主机 (apache) 转移到实时服务器 (nginx)
只有默认 link 有效,并且还遵循 codex 中的一般 WordPress 规则,但
我找不到文件路径 /etc/nginx/global/ 或 /etc/nginx/conf/global
当我搜索 .conf 文件时,它只显示这些文件:
/home/wwwroot/my-domain/etc/nginx-host-subdomain-template.conf
/home/wwwroot/my-domain/etc/nginx-host-template.conf
/home/wwwroot/my-domain/etc/php5.2-fpm-template.conf
/home/wwwroot/my-domain/etc/php-fpm-template.conf
/home/wwwroot/my-domain/etc/main.conf
/home/wwwroot/my-domain/php-fpm/go123.conf
/home/wwwroot/my-domain/vhost/go123.conf
/home/wwwroot/my-domain/rewrite/amh.conf
不知道要编辑什么文件才能在 codex 中插入代码。我第一次使用nginx
我假设你的 nginx html
目录位置是 /usr/share/nginx/html
而你的 nginx default.conf
位置是 /etc/nginx/conf.d/default.conf
好的,在编辑器上打开你的 nginx default.conf ( /etc/nginx/conf.d/default.conf
) 文件。并用以下服务器块内容替换文件
server {
listen 80;
server_name your-domain.com www.your-domain.com;
client_max_body_size 128m;
root /usr/share/nginx/html/your-wp-root-dir;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?q=$request_uri;
}
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_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
用您的域名更新 your-domain
并用您的 wp 根目录名称更新 your-wp-root-dir
。
然后使用sudo service nginx restart
或sudo /etc/init.d/nginx restart
重启你的nginx服务器
经过反复试验,终于成功了。主要问题是 mod_rewrite
未启用,所以我发现该文件位于此处 /home/wwwroot/my-domain/rewrite/amh.conf
并为 nginx 服务器制定了重写规则。
这是代码:
location / {
index index.php index.html;
if (!-e $request_filename)
{
rewrite ^/(.+)$ /index.php last;
}
}
干杯!
我已经将 Wordpress 站点从本地主机 (apache) 转移到实时服务器 (nginx) 只有默认 link 有效,并且还遵循 codex 中的一般 WordPress 规则,但 我找不到文件路径 /etc/nginx/global/ 或 /etc/nginx/conf/global
当我搜索 .conf 文件时,它只显示这些文件:
/home/wwwroot/my-domain/etc/nginx-host-subdomain-template.conf
/home/wwwroot/my-domain/etc/nginx-host-template.conf
/home/wwwroot/my-domain/etc/php5.2-fpm-template.conf
/home/wwwroot/my-domain/etc/php-fpm-template.conf
/home/wwwroot/my-domain/etc/main.conf
/home/wwwroot/my-domain/php-fpm/go123.conf
/home/wwwroot/my-domain/vhost/go123.conf
/home/wwwroot/my-domain/rewrite/amh.conf
不知道要编辑什么文件才能在 codex 中插入代码。我第一次使用nginx
我假设你的 nginx html
目录位置是 /usr/share/nginx/html
而你的 nginx default.conf
位置是 /etc/nginx/conf.d/default.conf
好的,在编辑器上打开你的 nginx default.conf ( /etc/nginx/conf.d/default.conf
) 文件。并用以下服务器块内容替换文件
server {
listen 80;
server_name your-domain.com www.your-domain.com;
client_max_body_size 128m;
root /usr/share/nginx/html/your-wp-root-dir;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?q=$request_uri;
}
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_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
用您的域名更新 your-domain
并用您的 wp 根目录名称更新 your-wp-root-dir
。
然后使用sudo service nginx restart
或sudo /etc/init.d/nginx restart
经过反复试验,终于成功了。主要问题是 mod_rewrite
未启用,所以我发现该文件位于此处 /home/wwwroot/my-domain/rewrite/amh.conf
并为 nginx 服务器制定了重写规则。
这是代码:
location / {
index index.php index.html;
if (!-e $request_filename)
{
rewrite ^/(.+)$ /index.php last;
}
}
干杯!