0

I've transferred Wordpress site from localhost(apache) to Live server(nginx) only default link is working and also follow General WordPress rules in codex but I couldn't find the file path /etc/nginx/global/ or /etc/nginx/conf/global

When I search .conf file it only shows this files:

/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

Don't know what file to edit to insert the code in codex. My first time to use nginx

winresh24
  • 687
  • 1
  • 6
  • 27
  • When transferring from local to live server you need to replace local links with live ones in your database. Use [search and replace tool](https://interconnectit.com/products/search-and-replace-for-wordpress-databases/) and then after you've done that, flush your permalinks. – dingo_d May 20 '16 at 09:11
  • Yes, all links are working when the Permalinks was set to Default, but when I change to other it's 404 – winresh24 May 20 '16 at 09:13
  • 1
    how do you manage the server? which host do you use? – StreetCoder Jun 02 '16 at 11:20

2 Answers2

1

I assume your nginx html directory location is /usr/share/nginx/html and your nginx default.conf location is /etc/nginx/conf.d/default.conf

Ok open your nginx default.conf ( /etc/nginx/conf.d/default.conf ) file on an editor. and replace the file with the following server block content

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;
    }
}

Update your-domain with your domain name and your-wp-root-dir with your wp root directory name.

and then restart your nginx server using sudo service nginx restart or sudo /etc/init.d/nginx restart

Sark
  • 4,458
  • 5
  • 26
  • 25
  • can you take a look at this on what location here is `default.conf` is located http://imgur.com/0UPzwSqthe highlighted one is the current websites. – winresh24 May 21 '16 at 01:23
  • It looks like managed hosting environment, do you have VPS or Shared hosting.? – Sark May 21 '16 at 10:00
  • that's the access they gave me. It's my first time to use nginx server. Where do you think the `.conf` file is located? I badly need your help. Thanks – winresh24 May 23 '16 at 01:18
  • It should be `/home/wwwroot/my-domain/etc/nginx-host-template.conf` that one, just rename `nginx-host-template.conf` to `default.conf` and place the above server block in it. the you should probably reload nginx config ( there should be some option for that in your hosting control panel ) – Sark May 23 '16 at 02:48
  • This should give you more insights : http://wiki.dreamhost.com/Nginx#Local_configuration_files – Sark May 23 '16 at 02:49
  • Still giving me 404 I follow your solutions, after I make a changes the url automatically update itself to postname and even I change it to wp-admin it doesn't work. – winresh24 May 23 '16 at 03:56
  • Hi I made a bounty for this hope you can help me. thanks – winresh24 Jun 02 '16 at 08:04
  • @winresh24 Which hosting provider you are using.? – Sark Jun 02 '16 at 14:48
1

After those trial and error finally make it works. The main problem is that mod_rewrite wasn't enable so I figured it out the file was located here /home/wwwroot/my-domain/rewrite/amh.conf and made a rewrite rule for nginx server. Here is the code:

location / {
        index index.php index.html;
        if (!-e $request_filename)
        {
                rewrite ^/(.+)$ /index.php last;
        }
}

Cheers!

winresh24
  • 687
  • 1
  • 6
  • 27