简体   繁体   English

在Nginx上使用WordPress永久链接怎么办?

[英]What to do with WordPress permalink on nginx?

I started a VPS yesterday and I installed WordPress and have done basic setup. 我昨天启动了VPS,并安装了WordPress,并已完成基本设置。 But what is the deal with permalink? 但是永久链接有什么处理呢? No one wish to use default ugly URL structure. 没有人希望使用默认的丑陋URL结构。 I tried to understand http://wiki.nginx.org/WordPress but funny thing is "I don't know where to insert those codes". 我试图了解http://wiki.nginx.org/WordPress,但有趣的是“我不知道在哪里插入这些代码”。 They probably think all of their readers are well known with nginx, that's not funny. 他们可能会认为所有读者都对Nginx十分了解,这并不好笑。

So, I am pretty sure .htaccess is not working in nginx. 因此,我很确定.htaccess在nginx中不起作用。 Now what? 怎么办? Where to place which code to make Custom permalink work? 在哪里放置使自定义永久链接起作用的代码? PS: You know, if I set a custom permalink then the output is 404 page like: PS:您知道,如果我设置了一个自定义的永久链接,则输出为404页,例如:

在此处输入图片说明

So please, I want a simple guide that tell like "edit demo.php file and place below code after X". 因此,请我提供一个简单的指南,告诉您“编辑demo.php文件并在X后面的代码下面”。

ADDITIONAL INFO: My webroot is /usr/share/nginx/html, and I have two WordPress there. 其他信息:我的webroot是/ usr / share / nginx / html,那里有两个WordPress。 First: /usr/share/nginx/html directory and second: /usr/share/nginx/html/video directory. 第一个:/ usr / share / nginx / html目录,第二个:/ usr / share / nginx / html / video目录。 I want pretty url for both of them. 我想为他们两个都提供漂亮的网址。 I chmod wp-content to 775 for both. 我将chmod wp-content都设置为775。

Nginx doesn't support .htaccess at all. Nginx根本不支持.htaccess。

Is your nginx setup correctly so that php files are being processed by php-fpm? 您的nginx安装是否正确,以便php-fpm处理php文件? Your error screen shot is unclear about that. 您的错误屏幕截图尚不清楚。

You have to edit your nginx config file and tell it to use the wordpress controller to direct requests through. 您必须编辑您的nginx配置文件,并告诉它使用wordpress控制器引导请求通过。

Your nginx.conf should have an http block, and within that a server block, and within that some location blocks. 您的nginx.conf应该有一个http块,在该服务器块内,在某些位置块内。 You need to find the correct server block and insert the following location block 您需要找到正确的服务器块并插入以下位置块

location / {
    # Check if a file or directory index file exists, else route it to index.php.
    try_files $uri $uri/ /index.php?$args;
}

Here is a complete example of a fully working wordpress nginx.conf I run: 这是我运行的完全正常工作的wordpress nginx.conf的完整示例:

user www-data;
worker_processes 1;
pid /run/nginx.pid;

events {
    worker_connections 1024;
    multi_accept on;
    use epoll;
}

http {
    client_max_body_size 20M;

    fastcgi_buffers 16 16k;
    fastcgi_buffer_size 32k;

    sendfile on;
    keepalive_timeout 30;
    types_hash_max_size 2048;
    server_tokens off;

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

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

    gzip on;
    gzip_disable "msie6";
    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/x-javascript text/xml application/xml application/xml+rss text/javascript;

    server {
        listen 80 default_server;
        server_name www.site.com;

        root /var/www;
        index index.php;

        location / {
            # Check if a file or directory index file exists, else route it to index.php.
            try_files $uri $uri/ /index.php?$args;
        }

        # pass the PHP scripts to FastCGI server
        location ~ \.php$ {
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM