Nginx for Wordpress在子目录中

时间:2017-08-11 15:34:04

标签: wordpress nginx static assets

我使用以下Nginx配置来运行我的Wordpress应用程序。 Wordpress文件位于我在根目录中创建的wordpress文件夹中。

  

的/ var / WWW /根目录/ WordPress的

在我将用于访问应用程序的域中,我需要再添加一条路径。

  

example.com/wordpress/custompath

nginx.conf

#user  nobody;
worker_processes 1;


error_log /var/log/nginx/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

events {

    worker_connections 1024;
}


http {

    #allows file uploads up to 8 megabytes
    client_max_body_size 50M;

    server_tokens off;
    include mime.types;
    default_type application/octet-stream;

    log_format main '$http_x_forwarded_for - $remote_user [$time_local] "$request" '
    '$status $body_bytes_sent "$http_referer" '
    '"$http_user_agent" "$http_x_forwarded_for"';

    access_log /var/log/nginx/access.log main;

    client_header_buffer_size 4k;
    large_client_header_buffers 4 16k;

    sendfile on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout 65;

    #gzip  on;

    # Websocket support
    #upstream websocket {
    #    server 127.0.0.1:<PORT>;
    #}
    server {

        listen 80;
        server_name localhost;

        #cookies default descomplica
        client_header_buffer_size 4k;
        large_client_header_buffers 4 16k;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;
        include /etc/nginx/aliases.conf;

        #location /ws {
        #    proxy_pass http://websocket;
        #    proxy_http_version 1.1;
        #    proxy_set_header Upgrade $http_upgrade;
        #    proxy_set_header Connection "Upgrade";
        #}

        location /wordpress/custompath {

            root /var/www/webroot;
            index index.php /wordpress/index.php;
            try_files $uri $uri/ /wordpress/index.php?$args;

            location ~ \.php$ {

                location ~ /\. {

                    deny all; access_log off; log_not_found off;
                }
                include /etc/nginx/fastcgi_params;
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
                fastcgi_param DOCUMENT_ROOT $realpath_root;
                fastcgi_param PATH_INFO $fastcgi_script_name;
            }
        }

        index index.php index.html index.htm;

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {

            root html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}
        location ~ /\. {

            deny all; access_log off; log_not_found off;
        }
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

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

            location ~ /\. {

                deny all; access_log off; log_not_found off;
            }
            include /etc/nginx/fastcgi_params;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_param SCRIPT_FILENAME /var/www/webroot$fastcgi_script_name;
            fastcgi_param PATH_INFO $fastcgi_script_name;
            fastcgi_param DOCUMENT_ROOT /var/www/webroot;
        }

    }

    include /etc/nginx/conf.d/*.conf;

}

使用此当前设置,所有静态都会给出404错误。我尝试了几次修改,但每次我都有不同的错误。我对nginx不太熟悉。

我需要在nginx配置中调整什么才能让Wordpress在我的上下文中运行?

0 个答案:

没有答案