Nginx location and try_files in subdirectory - nginx

I'm trying to configure nginx vhost for application and stucked.
App is in directory /site/verb
At this moment app have this kind of links and it is working:
http://example.com/verb/lt.php?some_args=some_args&some_args?some_args
What I need? I need add another link for my clients like below:
http://example.com/v/lt.php?some_args=some_args&some_args?some_args
It is only change from /verb to /v but I want to handle both (for compatibility reasons) with all arguments after .php extension.
Is it possible in nginx config? (I want to avoid creating symlinks in directory).
I tried symlinks but it is not good solution.

Related

Nginx - Custom configuration files location

I use Nginx with many domains. Some of these domains have custom configurations. I'm including these files inside the server blocks in the Nginx configurations.
For example:
server {
... some configurations things here...
include /var/somewhere/custom.conf;
etc.. etc..
}
The configuration files of Nginx are inside: /etc/nginx
To try and keep everything in one place and not have my custom configuration files all over the place I would like to place my custom configuration files inside /etc/nginx/some_directory
Can I create a sub directory inside /etc/nginx without it causing any issues with Nginx itself? I want to create /etc/nginx/some_directory/ and place my many custom configuration files inside it and include them.
I'm specifically asking this question because I don't want to break something on my production server.
If nginx doesn't know about a directory, it'll not touch it. You can verify that by greping against such pattern in nginx's codebase.
However, messing with a foreign folder structure might cause problems with permissions and ownership of the files, therefore either just use a pre-defined folders nginx prepared for you (/etc/nginx/sites-enabled and /etc/nginx/sites-available) which you can use with symlinks such as nginx itself does
# ls /etc/nginx/sites-enabled
default -> /etc/nginx/sites-available/default
# ls /etc/nginx/sites-available
default
otherwise you're getting into a situation what C/C++ programmers call an undefined behavior and there's no guarantee that what works now will work in the future / nginx doesn't change as well as the distro maintainers might mess with the folder structure and permissions for the packages in distro package manager.
Example:
Nginx might verify the full /etc/nginx tree's permissions and owners - if your folders/files don't match it might cause a warning or crash even. If it's installed by a package manager, it might cause issues when removing the package itself e.g. if the package manager attempts to remove only a known list of folders + afterwards the parent i.e. /etc/nginx by rmdir or similar. Situations you don't really want to get into and debug when you can use allowed folders or symlinks or your own folders that are not bound to an application or behavior except the one you define.

Wordpress on Nginx server - .htaccess vs. nginx.conf

I have recently changed from Apache to Nginx server and running a Wordpress installation that was migrated onto this new Nginx server.
I only just realised that (the server provider forgot to mention) that the .htaccess file is no longer supported and shouldn't be used with Nginx.
Instead the nginx.conf file should be used. I know I can convert the contents of my current .htaccess file to nginx.conf using one of the convertors, but I don't even have the nginx.conf file.
Can I just create one?? And If I create one, do I place it into the root where currently my .htaccess file is??
Do I then delete the existing .htaccess file?
How should I go about this?
You definitely have nginx.conf - without it, your site wouldn't work. It is in /etc/nginx/ folder, and some additional configs can exist there and in subfolders.
Standard recommendations for WordPress with nginx you can find here in Codex. But if your site works, you have nothing else to do.
Unlike Apache with .htaccess files, nginx does not use any configuration files in WordPress folders. Everything is centralized in /etc/nginx/.
.htaccess files are ignored by nginx and can be deleted or kept in WordPress folders - it doesn't matter.
However, if you have some non-standard tuning in .htaccess files, you should implement relevant directives in nginx conf files. Convertors not very good for it, and produce errors sometimes, unfortunately. You should learn Apache rules used and create similar for nginx by yourself.

Change the Wordpress URL

I would like to change the URL for my Wordpress:
From this: www.example.com/wordpress
To this: www.example.com/game
What do I need to do?
I tried renaming the Wordpress folder to game but this did not work. It caused a linkage problem with the bank-end database.
which server you are using.
if you are using apache or nginx you need to modify you vhost files accordingly to point to the right directory.
location of these file depend on you server's OS.
commonly it is in /etc/httpd/conf.d/ or /etc/apache2/conf.d/
Not open any file in this www.example.com/wordpress folder, Change permission this folder apply 755 permission, stop apache server or stop xampp. after rename your foder name and start apache server or xammp

Which nginx-config file is enabled, /etc/nginx/conf.d/default.conf or /etc/nginx/nginx.conf?

There are two config files around, /etc/nginx/conf.d/default.conf
and /etc/nginx/nginx.conf, but which one is enabled?
I am running CentOS6.4 and nginx/1.0.15.
Technically, nginx.conf is all that matters, if you define every thing inside there it would still work, but to keep things organized, they use include, somewhere at the end of nginx.conf you'll see include /etc/nginx/conf.d/* and in some distros you'll also find include /etc/nginx/sites-enabled/* this is a convention to keep things organized, you create your server blocks in that conf.d or sites-enabled folder and it would be included here as if it's written in the nginx.conf file.
Of course you can add your own include lines there normally and create your own new conf folder that would be auto included.
TIP: These files are included in alphabetical order, you need to keep that in mind if you don't specify any server as default_server, because first one would be the default.
the general configuration of nginx is in /etc/nginx/nginx.conf. /etc/nginx/conf.d/default.conf is used to configure the default virtual host. For this you can also use sites-available and sites-enabled.
You can find more details at a blog entry from digital ocean How To Configure The Nginx Web Server On a Virtual Private Server
for save time.
if you just have 1 site to host, nginx.conf is ok. but,
if you have 2~n sites, for more clear config, you should use conf.d fold.

Migrating Drupal

Currently I have a single drupal site installed on apache 2.2 with php 5.3 on RHEL 6. I am moving servers and am trying to migrate the site. I have imported the database and htaccess, but I cannot access any of the pages other than the root of the site.
You may need to disable clean URLs before exporting the database, try to add ?q= before each path.
That happens when:
a) Apache mod_rewrite is not enabled. If you have root access then do sudo a2enmod rewrite
or
b) .htaccess file at the root folder isn't there, so you need to copy it again.
Here's a troubleshoot check list for mod_rewrite issues:
Make sure Apache's rewrite module is enabled: sudo a2enmod rewrite.
Make sure original .htaccess file is there in the root of your Drupal installation.
Make sure that the existing .htaccess file is getting read by Apache. To test it, add a this line in the beginning of the file and you should get a 500 Internal Server Error: ThisIsReallyABadSyntax.
If the .htaccess file is not in effect, make sure that the AllowOverride directive in the main Apache config file (usually /etc/apache2/httpd.conf on debian-based distros) is set to All. It might be set to None by default.
Finally, make sure that the clean URLs feature is enabled in Drupal settings.
With the phpinfo(); compare all the server specs, just to be sure both server are quite the same or similar.
Steps to migrate Drupal correctly:
Go to Configuration
find Clean URLs
Disable tick inside!
Clean cache!
Download your site file
Download your database
Create new database in your new site
Transfer file and database
Log in
10.Do this step to enable Clean URLs:
It's work 100% guaranteed !
Steps:
1. Download - Dev version (7.x-dev)
2. Find file .htaccess
3. just copy it to your server
4. That's it !

Resources