zafarmd
By:
zafarmd

Virtual Host on Nginx Ubuntu

August 26, 2015 2.9k views
Nginx WordPress Linux Basics

Hello,
I am using Ubuntu installed Nginx & all needy thing to serve website..
I am beginner first time using nginx web server software.
my server block for every domain is..

    server_name my_domain.com www.my_domain.com;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /var/www/my_domain.com/public_html;
    }
location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.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;
    }

location ~ /\.ht {
 }
}

after this

sudo ln -s /etc/nginx/sites-available/my_domain.com /etc/nginx/sites-enabled/my_domain.com
sudo service nginx restart

My website dont work properly..

One my wordpress site homepage are working fine but any sub-pages means post or pages are not open.... & my 2nd wordpress site are working all fine..
One my php site post, pages or anything - when open showing only its homepage

Please anyone suggest What I missing to work proper
Your help would be appreciated
Thanks

5 comments
  • by Jesin A
    This tutorial will show you how to set up WordPress Multisite with subdomains on an Nginx web server. This allows you to run multiple unrelated websites, with their own domains, from a single WordPress admin panel.
  • MrPeppah. what you are suggested the link...Its only for setup WP multisite.....This is not What I want

  • WordPress pages, category-pages, wp-admin work fine...But Only site post are not working

  • Check your WordPress permalinks. Under settings.

  • Thanks MrPeppah for reply,

    my wp permalinks is the postname
    Important is- When I 'm setup WordPress permalinks is default..then http://my_domain/sample-post/ are work fine(when manually open) and http://my_domain/?p=123 not work...

    and Non-WP Site links are completely not work..If open any links then it show only homepage(not redirect)

    Confusing me a lot... The Biggest Brain Licker Web Server Is Nginx

    Request to all, Dont Use Nginx If you are going to host Multiple website..Nginx will Death You

3 Answers

one my WordPress site pages, category-pages, wp-admin work fine...But Only site post are not working

This is an easy fix, you could have had it running already. If you want your permalinks to get working in nginx add the following to your vhost:

#######################
# Permalinks

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

This should work for your permalinks, once done restart nginx. I don't understand from your post what other problems you have so if you got more problems, please give some explanation.

  • Problem with Nginx..I want use Multi site host....
    I setup following the step link:https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-virtual-hosts-server-blocks-on-ubuntu-12-04-lts--3
    But Multi Site host not work properly with Nginx
    I think nginx has many bugs

    by Etel Sverdlov
    This tutorial shows you how to set up a new directory, how to grant the correct permissions, how to add content to a new page, how to turn on virtual hosting, and how to, if needed, set up local hosts. Virtual Hosts are used to run more than one website or domain off of a single server and IP address. When used with nginx, virtual hosts are called Server Blocks. This tutorial covers setting up server blocks on an Ubuntu server.
  • This is the one of my wordpress conf .Please Check If I missing some/etc/nginx/sites-available/domain.net.conf

    server {
        listen 80; #default_server
        listen [::]:80; #default_server ipv6only=on
    
        root /var/www/domain.net/public_html;
        index index.php index.html index.htm;
    
        server_name domain.net www.domain.net;
    
        location / {
            try_files $uri $uri/ /index.php?$query_string;
        }
    
        error_page 404 /404.html;
        error_page 500 502 503 504 /50x.html;
        sendfile off;
        location = /50x.html {
            root /var/www/domian.net/public_html;
        }
    location ~ \.php$ {
            #fastcgi_pass 127.0.0.1:9000;
            fastcgi_split_path_info ^(.+\.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;
        }
    if (!-e $request_filename) {
     rewrite ^.*$ /index.php last;
    }
    
    location ~ /\.ht {
     }
    }
    
  • So? With a multisite you just need to do a few more actions. This configuration with rewriting should work in a mutlisite environment. There aren't alot of bugs in nginx, you just need to knoe how to work with it. You can easily find a tutorial how to setup a multisite: https://www.digitalocean.com/community/tutorials/how-to-set-up-wordpress-multisite-with-nginx-on-ubuntu-14-04

    by Jesin A
    This tutorial will show you how to set up WordPress Multisite with subdomains on an Nginx web server. This allows you to run multiple unrelated websites, with their own domains, from a single WordPress admin panel.
  • I think they guy are suggesting to setup Multi Site WP, not non wp site

  • Also I think you are not understand what I said, and problem with nginx.
    My sites has sum 20,000 visitor a day. and even my website is down.
    and You suggest me follow tutorial about Setup New LEMP installation with New WordPress multi site. this is not What I want or Need.
    I 'm really fuck this guy who writed this tutorial you are suggested the link, because the tutorial confusing a lot.

  • One my WordPress site Working fine, but other are not

Then explain in proper english, in an organized way what you got, where you got it and how you want it.
What doesnt work?
What setup do you have?
What setup do you want?
Give a good explenation

Have another answer? Share your knowledge.