Question

Nginx: multiple sites (including Wordpress) in multiple folders with droplet_ip/site_name as URL

Hello, I have a LEMP droplet on which I want to host few sites. For now I have two applications: PhpMyAdmin and a Wordpress site. But my Wordpress site is stored in “/srv/www/mysite/mysite/src” and I want to access to this site via the URL “x.x.x.x/mysite” (x.x.x.x is my droplet IP of course) because I can’t use a domain name for the moment. So I tried a lot of things (with locations, aliases, root…) but none has worked. My last config file (works for PhpMyAdmin but not for “mysite”):

server {
	listen 80;
	listen [::]:80;

	root /srv/www;
	index index.php index.html;

	# Hosts
	server_name localhost x.x.x.x;

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

	location /mysite/ {
		alias /srv/www/mysite/mysite/src;
	}

	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_split_path_info ^(.+\.php)(/.+)$;
		fastcgi_pass unix:/var/run/php5-fpm.sock;
		fastcgi_index index.php;
		include fastcgi_params;
	}
}

As I said I’ve made a lot of tests and none of them has worked (there are always errors 404 and 500)… So thanks in advance for your help! :-)


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# http://wiki.nginx.org/Pitfalls
# http://wiki.nginx.org/QuickStart
# http://wiki.nginx.org/Configuration
#
# Generally, you will want to move this file somewhere, and start with a clean
# file but keep this around for reference. Or just disable in sites-enabled.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##

# Default server configuration
#
server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /var/www/html;

    # Add index.php to the list if you are using PHP
    index index.html index.php index.htm;

    server_name example.com;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
        autoindex on;
    }

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

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

# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
#   listen 80;
#   listen [::]:80;
#
#   server_name example.com;
#
#   root /var/www/example.com;
#   index index.html;
#
#   location / {
#       try_files $uri $uri/ =404;
#   }
#}

@qmarlats Just change the root and the server name.

If you want I would give you my email address and configure your Droplet.

@qmarlats I know what you are doing wrong. You need to do this :

sudo ln -s /srv/mysite/mysite/src /srv/www
mv /src/www/src mysite

Now you can access example.com/mysite

This comment has been deleted