Can somebody shine a light?
This is the issue: I need to create a site on a server that runs Nginx. I have no experience with this server, so I have been sticking my nose in it.
I want to omit the index.php, so that
http://www.mydomain.com/index.php/welcome/index
becomes
http://www.mydomain.com/welcome/index
I then want to extract the /welcome/index so I can start and play with that in the MVC application. I have been looking around, but I get lost in the club of people that are likely doing their own configurations.
My question is if I can influence the server response as a client, like it is done with Apache through the htaccess file, or do I need to involve the provider who is hosting the server? I have requested to alter the server for this, but the support I get is not very helpful.
I was able to simulate the required server response within the nginx.conf file. This tells me that it can be done.
For those interested. Read the values on the url through $_SERVER[‘REQUEST_URI’].
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
#keepalive_timeout 0;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root html;
index index.php index.html index.htm;
try_files $uri $uri/ /index.php;
}
include mime.types;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# 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 $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}
I do it like this:
And then you access the URI with
$_GET['uri']from yourindex.php. You should take a look at nginx’s try_files documentation.Or if you want to access it via
$_SERVER['REQUEST_URI']do it like this:Edit:
A few things just looking at your server conf:
You’ve already included mime.types in the
httpblock, so there is no need to include them again in theserverblockProbably a good idea to move
root html;andindex index.php...up to yourserverblockDefinitely read through these sample configurations (everything explained in the comments), very good way to start getting the hang of nginx conf
Nginx website has some really good resources