使用Nginx的Wordpress路由在Digital Ocean中不起作用

问题描述

从现在开始,我一直在为此苦苦挣扎,并想向社区询问。

我最近开始研究数字海洋和Nginx。我以前使用的是Apache。

我有一个简单的wordpress网站,在本地工作正常,但是当使用nginx在Droplet服务器上推送时,该网站无法正常工作。

目标网页运行正常,但是当我路由到其他链接时,我从nginx收到404错误页面。

我觉得这是因为htaccess文件在nginx中没有被拾取,我不得不在nginx中重写规则,但是没有任何作用。

这是我的nginx.conf文件的配置文件,网站可用/默认文件

网站可用/默认

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    client_max_body_size 100M;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;
    ##
    # SSL Settings
    ##

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3,ref: POODLE
    ssl_prefer_server_ciphers on;

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/javascript text/xml     application/xml application/xml+rss text/javascript;
    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

nginx.conf

{{1}}

有什么建议可以帮助我解决这个问题吗?

解决方法

站点可用/默认文件中有两个服务器块。第一个服务器块接收HTTP请求,然后以重定向指令响应第二个服务器块定义的HTTPS版本。您只需要将前3行保留在第一个代码块内,然后像这样删除其余的代码即可:

server {
    listen 80;
    server_name martinschildrenacademy.com www.martinschildrenacademy.com;
    return 301 https://$host$request_uri;
}

WordPress的Nginx配置必须具有以下位置块才能正常工作:

location / {
        # This is cool because no php is touched for static content.
        # include the "?$args" part so non-default permalinks doesn't break when using query string
        try_files $uri $uri/ /index.php?$args;
}

因此,您必须将位置块插入第二个服务器块。你做到了而且有效。

,

就可以了。

不确定为什么,但我只是移动了这一行

location / {
        # This is cool because no php is touched for static content.
        # include the "?$args" part so non-default permalinks doesn't break when using query string
        try_files $uri $uri/ /index.php?$args;
}
从顶部到底部服务器块中的

在default.config文件中。而且有效。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...