I'm using YII framework. I can access my site through: localhost/index.php
then If I click any links on it it says: 404 not found.
It works on Apache. I'm trying to configure it with NGINX with no success. Can somebody please tell me what can be the problem if something works with Apache but does not work with NGINX?
Log error from nginx:
2011/05/07 11:27:42 [error] 5104#3152: *30 CreateFile() "c:\EWemp\nginx-0.8.52/html/rooms/finished" failed (3: The system cannot find the path specified), client: 127.0.0.1, server: localhost, request: "GET /rooms/finished HTTP/1.1", host: "localhost", referrer: "http://localhost/index.php"
So, I assume that it needs some kind of URL rewrite, since I do not have html/rooms/finished directory.
It is like html/controller/action/ but I do not know what to change in order to get it to work
Yii uses one index.php file to handle all client requests. You need to rewrite /rooms/finished to index.php/rooms/finished.
I have used this Nginx configuration to rewrite all requests to be handled by one index.php file. This configuration uses Fast-CGI to pass PHP requests to PHP-FPM. If you use proxy_pass, you can use rewrite. proxy_pass is explained here.
location / {
index index.php; # Set the index file
try_files $uri $uri/ #handler; # If missing pass the URI to front handler
}
location #handler {
rewrite / /index.php;
}
location ~ .php$ {
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param SCRIPT_FILENAME PATH_TO_SCRIPT$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
}
In my opinion, may be you should make ".htaccess file" like in Apache.
Related
I've a nuxt.js app behind nginx reverse proxy. The nginx conf file looks like this:
server {
listen 80;
# Match *.lvh.me
server_name ~^(?<user>.+)\.lvh\.me$;
location / {
proxy_pass http://localhost:8080/sites/$user$uri$is_args$args;
}
location ~* \.(?:js|css|jpg|jpeg|gif|png|ico|cur|svg)$ {
proxy_pass http://localhost:8080;
}
}
As you can see I'm mapping all my site subdomains to a specific path on my site and it is working fine. I'm also mapping all assets to be loaded from the root (because otherwise it throws a 404 error).
The only issue I'm facing is the whenever I visit a subdomain e.g subdomain.lvh.me it loads two pages on top of each other, the original page from subdomain root (which is expected) but also the page from the main domain root i.e. lvh.me (which is not expected).
Can you please checkout my conf file to see if I'm doing anything wrong here?
So I've encountered this issue and what I did to fix it was to not rely on Nginx's root nor proxy_pass. Instead, I used a location block with an alias and a try_files inside like so:
location ^~ / {
alias /path/to/dist;
try_files $uri $uri/ /index.html = 404;
}
I'm trying to set up a quick temp API for a project i'm working on
My current nginx conf :
listen 80;
server_name app.domain.com
root /var/www/html/public;
index index.html index.php:
rewrite ^/api/v1/([^/]+)/([^/]+)/?$ /apiv1.php?class=$1method=$2? last;
location / {
try_files $uri $uri/ /index.php;
}
+ standard fpm config
While this works for urls like /api/v1/type/subtype ,
I need to be able to request to url in a format like this :
/api/v1/organisation/{id}/teams
/api/v1/organisations/{id}/teams/{id}
How can I get an unlimited amount of possible parameters in my url?
It's much easier to parse URL with PHP, not with Nginx. You can create a location that would handle all "/api/v1" requests and proxy_pass them to apiv1.php, which in turn would do all the rest.
So I'm trying to install ZoneMinder and have it run under Nginx, but it has a few compiled files that need to be run using Fast-CGI. These files lack an extension.
If the file has an extension, then there is no issue and Nginx interprets it as a file and will just return a 404 if it can't find it. If it has no extension, it will assume it's a directory and then eventually return a 404 when it can't find any sort of index page.
Here is what I have now:
# Security camera domain.
server {
listen 888;
server_name mydomain.com;
root /srv/http/zm;
# Enable PHP support.
include php.conf;
location / {
index index.html index.htm index.php;
}
# Enable CGI support.
location ~ ^/cgi-bin/(.+)$ {
alias /srv/cgi-bin/zm/;
fastcgi_pass unix:/run/fcgiwrap.sock;
fastcgi_param SCRIPT_FILENAME $document_root/$1;
include fastcgi.conf;
}
}
The idea is, anything under the cgi-bin directory goes through the fastcgi pipe.
Any idea on howI can fix this?
Upon closer inspection, I realized ZoneMinder only has two cgi scripts (nph-zms, zms), so it was easier just to explicitly state them in nginx as so:
# Enable CGI support.
location ~ ^/cgi-bin/(nph-zms|zms)$ {
alias /srv/cgi-bin/zm/;
fastcgi_pass unix:/run/fcgiwrap.sock;
fastcgi_param SCRIPT_FILENAME $document_root/$1;
include fastcgi.conf;
}
Seems to be the best way to go :)
I am facing the following problem when migrating from apache to nginx:
When deploying a folder named "apps" including about 10 subfolders with zend framework 2 apps, I am not able to browse my zf-routes (http 404).
This happens because my htaccess is not read and my rewrite does not take place.
It would work when defining all projects in my nginx config but this is not very dynamic and all new projects would need a new entry while apache read the .htaccess in all folders and did it on itself.
Is there any nginx directive I did not find to accomplish this?
I am currently trying this codeblock:
location /apps/ {
try_files $uri $uri/ /index.php;
}
I know this would cause nginx to check /apps/index.php instead of /apps/(projectname)/index.php - but I don't know how to change this.
location /apps/(.*)/ {
try_files $uri $uri/ /apps/(.*)/index.php?$args;
}
This is the solution. I just missed the part before index.php.
I want to set up a Mono ASP.NET on Nginx, but it seems the index priority does not work.
If I use the example from http://www.mono-project.com/FastCGI_Nginx as following:
location / {
root /srv/www/htdocs/;
index index.htm index.html default.aspx Default.aspx;
fastcgi_index Default.aspx;
fastcgi_pass 127.0.0.1:9000;
include /etc/nginx/fastcgi_params;
}
Then when I visit http://localhost/, it will always request Default.aspx, and if there is no such file, the web server will show a 404 error.
I tried to find answer by search the question, and I found this one:
asp mvc home root not working with mono, fastcgi and nginx
So I guess I meet the same issue, then I modified the config file as following:
location / {
root /srv/www/htdocs/;
index index.htm index.html default.aspx Default.aspx;
fastcgi_index /;
fastcgi_pass 127.0.0.1:9000;
include /etc/nginx/fastcgi_params;
}
The web server still requests .aspx-files as priority, even if I have only one .aspx file such as random.aspx in the htdocs folder, it will still show it before index.htm.
And then when I removed all FastCGI related config as following:
location / {
root /srv/www/htdocs/;
index index.htm index.html default.aspx Default.aspx;
}
Only in this way the index priority works correctly.
So who can tell me, why does this happen? Do I have to modify any config file that is related to FastCGI?
Make sure when your fastcgi settings in monoserve are pointing to a valid path.
fastcgi-mono-server2 /applications=www.domain1.xyz:/**:/var/www/www.domain1.xyz**/ /socket=tcp:127.0.0.1:9000
/var/www/www.domain1.xyz/ must point to the root directory of your web app.