nginx match no found when using a query string - nginx

I am a little stuck with Nginx not behaving as I expect it to?
When making a curl request to curl -I http://example.com/schedule/ajax.php I get the expected output of HTTP/1.1 200 OK
However, when I add a query string it fails curl -I http://example.com/schedule/ajax.php?m=item with no matches found: http://example.com/schedule/ajax.php?m=item
Additionally:
this project has Drupal which is fully functioning and its Nginx root is at / (as
in Drupal's index.php file is in /app/web/)
then the schedule directory is not a Drupal and if files are in /app/web/schedule/
the ajax.php is a special case as all other requests are processed by
index.php so for example http://example.com/schedule/view is
processed be /schedule/index.php (yes not /app/web/index.php)
so the short version is /schedule is not Drupal but / is
So my question is why do requests to http://example.com/schedule/ajax.php?m=item fail?
My nginx config is
server {
listen ${NGINX_LISTEN:-8080} default_server;
include /etc/nginx/helpers/*.conf;
root /app/${WEBROOT:-};
index index.php;
## rewriting /index.php to / because after https://www.drupal.org/node/2599326
## autocomplete URLs are forced to go to index.php
rewrite ^/index.php / last;
location /schedule/ajax.php {
add_header X-debug-message-ajax "a: $args q:$query_string" always;
#return 403;
try_files $uri /schedule/ajax.php?$args;
}
location /schedule/ {
## Disallow access to any dot files, but send the request to wordpress
location ~* /\. {
try_files /dev/null #php;
}
## Direct Access to .php files is not alled and is sent to wordpress instead
location ~* ^.+\.php$ {
try_files /dev/null #php;
}
## Try to find a file with given URL, if not pass to wordpress
try_files $uri /schedule/$uri/ /schedule/index.php?$args;
}
## The 'default' location.
location / {
include /etc/nginx/conf.d/drupal/location_prepend*.conf;
## Do not allow access to .txt and .md unless inside sites/*/files/
location ~* ^(?!.+sites\/.+\/files\/).+\.(txt|md)$ {
deny all;
access_log off;
log_not_found off;
}
## Replicate the Apache <FilesMatch> directive of Drupal standard
## .htaccess. Disable access to any code files. Return a 404 to curtail
## information disclosure.
location ~* \.(engine|inc|install|make|module|profile|po|sh|.*sql|.*sql\.gz|theme|twig|tpl(\.php)?|xtmpl|yml)(~|\.sw[op]|\.bak|\.orig|\.save)?$|^\/(\.(?!well-known).*|Entries.*|Repository|Root|Tag|Template|composer\.(json|lock))$|^\/#.*#$|\.php(~|\.sw[op]|\.bak|\.orig|\.save)$ {
deny all;
access_log off;
log_not_found off;
}
## Expiring per default for four weeks and one second, Drupal will overwrite that if necessary
expires ${NGINX_DEFAULT_EXPIRES:-2628001s};
## Disallow access to any dot files, but send the request to Drupal
location ~* /\. {
try_files /dev/null #drupal;
}
### Directives for installing drupal.
location ~* ^(/install.php|/core/install.php) {
try_files /dev/null #php;
}
## Direct Access to .php files is not allowed and is sent to Drupal instead
location ~* ^.+\.php$ {
try_files /dev/null #drupal;
}
## Try to find a file with given URL, if not pass to Drupal
try_files $uri #drupal;
}
## Main Drupal Location
location #drupal {
add_header X-debug-message-drupal "1" always;
include /etc/nginx/conf.d/drupal/location_drupal_prepend*.conf;
include /etc/nginx/fastcgi.conf;
fastcgi_param SCRIPT_NAME /index.php;
fastcgi_param SCRIPT_FILENAME $realpath_root/index.php;
fastcgi_pass ${NGINX_FASTCGI_PASS:-php}:9000;
include /etc/nginx/conf.d/drupal/location_drupal_append*.conf;
}
## PHP Location.
## Warning: This allows to execute any PHP files, use with care!
location #php {
add_header X-debug-message-php "$realpath_root : $fastcgi_script_name : $args" always;
include /etc/nginx/conf.d/drupal/location_php_prepend*.conf;
include /etc/nginx/fastcgi.conf;
fastcgi_pass ${NGINX_FASTCGI_PASS:-php}:9000;
include /etc/nginx/conf.d/drupal/location_php_append*.conf;
}
## Trying to access private files directly returns a 404.
location /sites/default/files/private/ {
internal;
}
}

As pointed out in the comments the issue was not with Nginx it was actually an error in my curl request.

Related

public ressources not accessible

I'm tring to access the bundles directory (which is located in : /usr/src/app/public/bundles) of my symfony project.
But, all files in public dir can't be accessed with my navigator. eg:
Request URL: http://localhost:8080/bundles/easyadmin/app.css
Request Method: GET
Status Code: 404 Not Found
The file exists...
This is my nginx config :
server {
server_name ~.*;
location / {
root /usr/src/app;
try_files $uri /index.php$is_args$args;
}
client_max_body_size 100m;
location ~ ^/index\.php(/|$) {
if ($request_method ~* "(GET|POST|PATCH|DELETE)") {
add_header "Access-Control-Allow-Origin" '*' always;
}
# Preflighted requests
if ($request_method = OPTIONS ) {
add_header "Access-Control-Allow-Origin" '*' always;
add_header "Access-Control-Allow-Methods" "GET, POST, PATCH, DELETE, OPTIONS, HEAD";
add_header "Access-Control-Allow-Headers" "Authorization, Origin, X-Requested-With, Content-Type, Accept";
return 200;
}
fastcgi_pass php:9000;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
fastcgi_read_timeout 600;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /usr/src/app/public/index.php;
}
# return 404 for all other php files not matching the front controller
# this prevents access to other php files you don't want to be accessible.
location ~ \.php$ {
return 404;
}
error_log /var/log/nginx/project_error.log;
access_log /var/log/nginx/project_access.log;
}
I don't know what is missconfigured...
Without seeing any error log I can just guess the issue but lets check directories you are using.
First of all try to avoid root in locations.
Putting root inside of a location block will work and it’s perfectly valid. What’s wrong is when you start adding location blocks. If you add a root to every location block then a location block that isn’t matched will have no root. Therefore, it is important that a root directive occur prior to your location blocks, which can then override this directive if they need to.
The configuration should look like this:
root /usr/src/app/public/;
location / {
try_files $uri /index.php$is_args$args;
}
Your location is missing the public directory. So why do see the 404:
For this request http://localhost:8080/bundles/easyadmin/app.css with your configuration NGINX will look into /usr/src/app/ for /bundles/easyadmin/app.css. And it will not be able to find it. But /usr/src/app/public/bundles/easyadmin/app.css` will be a valid path and should result in 200 OK.

Nginx screen pops up on website homepage but rest of site works fine

I am working with a localhost site and been checking my nginx configuration files over and over again because the default homepage screen shows the 'WELCOME TO NGINX!" title. After awhile I figured out by typing /user I was able to by-pass the homescreen and actually able to login to the site. Everything works EXCEPT the homepage screen, which gets directed to the NGINX home screen page. I'm a bit a a loss as to why this is. Here is my nginx conf file:
server {
server_name zeragames.localhost;
root /var/www/html/zeragames/web; ## <-- Your only path reference.
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
# Very rarely should these ever be accessed outside of your lan
location ~* \.(txt|log)$ {
allow 192.168.0.0/16;
deny all;
}
location ~ \..*/.*\.php$ {
return 403;
}
location ~ ^/sites/.*/private/ {
return 403;
}
# Block access to scripts in site files directory
location ~ ^/sites/[^/]+/files/.*\.php$ {
deny all;
}
# Allow "Well-Known URIs" as per RFC 5785
location ~* ^/.well-known/ {
allow all;
}
# Block access to "hidden" files and directories whose names begin with a
# period. This includes directories used by version control systems such
# as Subversion or Git to store control files.
location ~ (^|/)\. {
return 403;
}
location / {
# try_files $uri #rewrite; # For Drupal <= 6
try_files $uri /index.php?$query_string; # For Drupal >= 7
}
location #rewrite {
#rewrite ^/(.*)$ /index.php?q=$1; # For Drupal <= 6
rewrite ^ /index.php; # For Drupal >= 7
}
# Don't allow direct access to PHP files in the vendor directory.
location ~ /vendor/.*\.php$ {
deny all;
return 404;
}
# Protect files and directories from prying eyes.
location ~* \.(engine|inc|install|make|module|profile|po|sh|.*sql|theme|twig|tpl(\.php)?|xtmpl|yml)(~|\.sw[op]|\.bak|\.orig|\.save)?$|/(\.(?!well-known).*)|Entries.*|Repository|Root|Tag|Template|composer\.(json|lock)|web\.config$|/#.*#$|\.php(~|\.sw[op]|\.bak|\.orig|\.save)$ {
deny all;
return 404;
}
# In Drupal 8, we must also match new paths where the '.php' appears in
# the middle, such as update.php/selection. The rule we use is strict,
# and only allows this pattern with the update.php front controller.
# This allows legacy path aliases in the form of
# blog/index.php/legacy-path to continue to route to Drupal nodes. If
# you do not have any paths like that, then you might prefer to use a
# laxer rule, such as:
# location ~ \.php(/|$) {
# The laxer rule will continue to work if Drupal uses this new URL
# pattern with front controllers other than update.php in a future
# release.
location ~ '\.php$|^/update.php' {
fastcgi_split_path_info ^(.+?\.php)(|/.*)$;
# Ensure the php file exists. Mitigates CVE-2019-11043
try_files $fastcgi_script_name =404;
# Security note: If you're running a version of PHP older than the
# latest 5.3, you should have "cgi.fix_pathinfo = 0;" in php.ini.
# See http://serverfault.com/q/627903/94922 for details.
include fastcgi_params;
# Block httpoxy attacks. See https://httpoxy.org/.
fastcgi_param HTTP_PROXY "";
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param QUERY_STRING $query_string;
fastcgi_intercept_errors on;
# PHP 5 socket location.
#fastcgi_pass unix:/var/run/php5-fpm.sock;
# PHP 7 socket location.
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
try_files $uri #rewrite;
expires max;
log_not_found off;
}
# Fighting with Styles? This little gem is amazing.
# location ~ ^/sites/.*/files/imagecache/ { # For Drupal <= 6
location ~ ^/sites/.*/files/styles/ { # For Drupal >= 7
try_files $uri #rewrite;
}
# Handle private files through Drupal. Private file's path can come
# with a language prefix.
location ~ ^(/[a-z\-]+)?/system/files/ { # For Drupal >= 7
try_files $uri /index.php?$query_string;
}
# Enforce clean URLs
# Removes index.php from urls like www.example.com/index.php/my-page --> www.example.com/my-page
# Could be done with 301 for permanent or other redirect codes.
if ($request_uri ~* "^(.*/)index\.php/(.*)") {
return 307 $1$2;
}
}
host file:
127.0.0.1 localhost
127.0.0.1 zeragames.localhost
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
My main question: How do I get the homepage screen to work showing Welcome to Drupal 8! instead of pointing to the NGINX homescreen? As stated above, every other page works and is accessible. Just the homepage itself isn't!

How to remove index,php from CI project url to make clean url in nginx Hostwinds server, when CI project is inside subdirectory?

"I'm setting up an Nginx server on Hostwinds for CI project which is in a subdirectory. Where I want to make a clean URL by removing index.php. Initially, this project was running on Apache server and with the help of .htaccess file, I have made a clean URL by removing index.php. But .htaccess file not works on the Nginx server. So, tell me what codes should I use to remove index.php from URL in 'Hostwinds' Server.
In subdirectory home page of projects opens but when you click on any of its links it will redirects you to 404 page.
I have tried various solution which is available on the internet but none of them worked for me. I have used this code inside nginx.conf file.
some of them:-
1)
location /category/subcategory {
try_files $uri $uri/ /category/subcategory/index.php;
}
2)
location /subfoldername/ {
root /usr/share/nginx/www/subfoldername;
try_files $uri $uri/ /index.php?$query_string;
}
3)
location /api/ {
alias /var/www/api/;
try_files $uri $uri/ /api/index.php;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
fastcgi_pass backend;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
}
}
4)
location /nested {
alias /var/www/nested/public;
try_files $uri $uri/ /index.php$is_args$args;
}
...http {...
server {
listen 443 ssl http2;
#listen [::]:443 ssl http2 ipv6only=off;
server_name example.com;
location / {
index index.html index.htm index.php;
try_files $uri $uri/ #backend;
}
location #backend {
include proxy_params_common;
# === MICRO CACHING ===
# Comment the following line to disable 1 second micro-caching for dynamic
HTML content
include proxy_params_dynamic;
}
# Enable browser cache for static content files (TTL is 1 hour)
location ~* \.(?:json|xml|rss|atom)$ {
include proxy_params_common;
include proxy_params_static;
expires 1h;
}
# Enable browser cache for CSS / JS (TTL is 30 days)
location ~* \.(?:css|js)$ {
include proxy_params_common;
include proxy_params_static;
expires 30d;
}
# Enable browser cache for images (TTL is 60 days)
location ~* \.(?:ico|jpg|jpeg|gif|png|webp)$ {
include proxy_params_common;
include proxy_params_static;
expires 60d;
}
# Enable browser cache for archives, documents & media files (TTL is 60 days)
location ~* \.
(?:3gp|7z|avi|bmp|bz2|csv|divx|doc|docx|eot|exe|flac|flv|gz|less|mid|midi|mka|mkv|mov|mp3|mp4|mpeg|mpg|odp|ods|odt|ogg|ogm|ogv|opus|pdf|ppt|pptx|rar|rtf|swf|tar|tbz|tgz|tiff|txz|wav|webm|wma|wmv|xls|xlsx|xz|zip)$ {
set $CACHE_BYPASS_FOR_STATIC 1;
include proxy_params_common;
include proxy_params_static;
expires 60d;
}
# Enable browser cache for fonts & fix #font-face cross-domain restriction (TTL is 60 days)
location ~* \.(eot|ttf|otf|woff|woff2|svg|svgz)$ {
include proxy_params_common;
include proxy_params_static;
expires 60d;
#add_header Access-Control-Allow-Origin *;
}
# Prevent logging of favicon and robot request errors
location = /favicon.ico {
include proxy_params_common;
include proxy_params_static;
expires 60d;
log_not_found off;
}
location = /robots.txt {
include proxy_params_common;
include proxy_params_static;
expires 1d;
log_not_found off;
}
# Deny access to files like .htaccess or .htpasswd
location ~ /\.ht {
deny all;
}
}
Initially link:- www.example.com/index.php/search-result
resulted in link:- www.example.com/search-result

Restricting access by IP address to wp-admin and wp-login.php on Azure Wordpress on Linux

Using Azure Wordpress for Linux Web App, I'm trying to modify the nginx conf.d file to restrict access to wp-login.php and wp-admin directory by IP address. The directives that I'm trying to use either seem to completely allow access or completely deny access, it does not seem to respect allow x.x.x.x; at all.
Here is the code that I've placed in my server block:
location ~ ^(wp-admin|wp-login.php) {
try_files $uri $uri/ /index.php?$args;
index index.html index.htm index.php;
allow x.x.x.x;
deny all;
}
If I only have the deny all; directive, everything returns a 403 forbidden error. If I put in the allow directive, I can access it from any IP address and it never seems to throw an error.
I've noticed in my logs that this is showing up:
278#278: *25 access forbidden by rule, client: 172.19.0.1, server: _, request: "GET /wp-admin HTTP/1.1", host: "myhostname.com"
and that this precedes my server block in the default.conf file:
upstream php {
#server unix:/tmp/php-cgi.socket;
server 127.0.0.1:9000;
}
Is these something going on that basically makes all my inbound traffic appear to nginx as coming from the same IP address? Is there any way to "pass that down" ?
Here is the default.conf file:
upstream php {
server unix:/var/run/php/php7.0-fpm.sock;
#server 127.0.0.1:9000;
}
server {
listen 80;
## Your website name goes here.
server_name _;
## Your only path reference.
root /home/site/wwwroot;
## This should be in your http block and if it is, it's not needed here.
index index.php index.html;
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
# Add locations of phpmyadmin here.
# Disable sendfile as per https://docs.vagrantup.com/v2/synced-folders/virtual
sendfile off;
set $skip_cache 0;
# POST requests and urls with a query string should always go to PHP
if ($request_method = POST) {
set $skip_cache 1;
}
if ($query_string != "") {
set $skip_cache 1;
}
# Don't cache uris containing the following segments
if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml") {
set $skip_cache 1;
}
# Don't use the cache for logged in users or recent commenters
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
set $skip_cache 1;
}
# Don't cache WooCommerce URLs
# Cart widgets are still a problem: https://github.com/emcniece/docker-wordpress/issues/3
if ($request_uri ~* "/(cart|checkout|my-account)/*$") {
set $skip_cache 1;
}
location / {
# This is cool because no php is touched for static content.
# include the "?$args" part so non-default permalinks doesn't break when using query string
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
include fastcgi.conf;
fastcgi_intercept_errors on;
fastcgi_pass php;
fastcgi_read_timeout 300;
fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache;
fastcgi_cache WORDPRESS;
fastcgi_cache_valid 60m;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
I started noticing today that I can see the IP address that I want under the PHP variable of $_SERVER['HTTP_X_CLIENT_IP'] --- Is there a way to test that under the allow/deny options, or to override the value that allow/deny looks at to use this other value? For example:
if ($http_x_client_ip != x.x.x.x) {
return 403;
}

Nginx config for Yii 2 Advanced App Template

I would like to configure the Nginx web-server in such a way that:
Requests to the /index.php URI should be handled by public_html/frontend/web/index.php
Requests to the /admin/index.php URI should be handled by public_html/backend/web/index.php
Advice please where I'm wrong. Here is my config:
server {
listen 80;
server_name yii2.lo;
server_tokens off;
client_max_body_size 128M;
charset utf-8;
access_log /var/log/nginx/yii2-access.log main buffer=50k;
error_log /var/log/nginx/yii2-error.log notice;
set $host_path "/srv/http/yii2/public";
set $yii_bootstrap "index.php";
index $yii_bootstrap;
location / {
root $host_path/frontend/web;
try_files $uri $uri/ /$yii_bootstrap?$args;
}
location /admin {
root $host_path/backend/web;
try_files $uri $uri/ /$yii_bootstrap?$args;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index $yii_bootstrap;
# Connect to php-fpm via socket
fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
fastcgi_connect_timeout 30s;
fastcgi_read_timeout 30s;
fastcgi_send_timeout 60s;
fastcgi_ignore_client_abort on;
fastcgi_pass_header "X-Accel-Expires";
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param HTTP_REFERER $http_referer;
include fastcgi_params;
}
location ~* \.(js|css|less|png|jpg|jpeg|gif|ico|woff|ttf|svg|tpl)$ {
expires 24h;
access_log off;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
log_not_found off;
access_log off;
}
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
}
Long story short: use the first method provided below.
The rest of the answer is a list of recommendations.
I'm going to separate my answer in two sections.
In the first part, I will tell you the easiest and the fastest way to achieve your goal according to your desired URL requests, but it partly breaks the app structure, nothing serious, though.
In the second part, I will describe you where you made mistakes in your configuration file and I will show you a poorly written configuration for your needs which works.
I. Shared Hosting deployment
I highly encourage you to use this. This is an official way from Yii 2 documentation to make backend work at the same domain, although it helps to deploy a project to a shared hosting. And it doesn't require any additional nginx configuration, just a basic one for frontend root.
Let me write a simple list according to this guide:
Move contents from /backend/web to /frontend/web/admin.
Correct scripts' paths in /frontend/web/admin/index.php (and index-test.php, if you use it)
That's all, you have your backend at the same domain at /admin URL. Additionally, read the last section of the guide regarding cookies. The advanced template was designed to use different domains for each environment, therefore the guide describes backend config for shared hosting to keep cookies from frontend and backend separate.
Of course, don't forget to modify your /environments files for proper initialization of your project with /init script.
II. Nginx configuration
Mistakes
I'm not a profressional nginx administrator, but I can describe what's wrong in your configuration based on my personal experience and the documentation. Unfortunately, I won't be able to provide links to the documentation, because my current rating won't allow me to post more than 2 links.
Server context root
You do not have root directive in your server context. Thus, when ~ \.php$ location is matched, it doesn't have root at all and uses default nginx root. Try setting common root directive in the server context, then all locations will have it by default. For example:
server {
# Beginning of your configuration
# ...
root /srv/http/yii2/public/frontend/web;
# The rest of your configuration
# ...
}
Not having a higher context root is a common pitfall.
root instead of alias
Secondly, when a location is matched, the uri is appended to the location's root and that's the path the server attempts to look for. Thus, your /admin location suggests that the server search for $host_path/backend/web/admin. In your situation, you should use alias directive which tells the server that the matched location uri refers to alias path, not appended to root:
location /admin {
alias $host_path/backend/web;
# The rest of location
# ...
}
I recommend that you read related nginx documentation about location, root and alias directives.
Working but poorly written configuration
I post this sample configuration with comments for your understanding only, not for production use, I dicourage you to apply it for your production (until you're positive it's safe and sound).
It works, but it has an annoying defect: backend cannot find Yii2 entry script if you request it directly (like /admin/index.php), so it must be used with enablePrettyUrl set to true and showScriptName set to false, however it finds any other PHP script in the backend web root.
server {
# The beginning of your configuration
# ...
# By default we will provide frontend
root /srv/http/yii2/public/frontend/web;
index index.php;
location / {
try_files $uri $uri/ /index.php?$args;
}
location /admin {
# We use /web/index here to make backend call to php scripts
# distinct from frontend call
index /web/index.php;
alias $root_base/backend/web;
try_files $uri $uri/ /web/index.php?$args;
# Rewrite PHP requests from /admin to /web
# However, Yii2 entry script returns 404
location ~ ^/admin/.*\.php$ {
rewrite ^/admin/(.*)$ /web/$1;
}
}
location ~ ^/web/.*\.php$ {
# Make sure this location cannot be called externally
internal;
# Remember, that the uri of this location
# will be appended to this root!
root $root_base/backend;
# PHP settings for backend
}
location ~ \.php$ {
# PHP settings for frontend
}
# The rest of your configuration
# ...
}
Additionally, add baseUrl property to the request component in your Yii2 backend config and set it to /admin.
I hope my answer will help you deploying your Yii2 advanced project and understanding nginx more, nevertheless your question is 6 months old.
Here's my working config, based on accepted answer. My project backend directory is renamed to admin
# Example config for nginx
# frontend is available on yii-application.local/
# backend (admin) is available on yii-application.local/admin
# make sure that #app/frontend/config/main.php and #app/admin/config/main.php components sections are configured properly
# e.g. #app/frontend/config/main.php
# 'homeUrl' => '',
# ...
# 'components' => [
# 'request' => [
# 'baseUrl' => '',
# ],
# 'urlManager' => [
# 'enablePrettyUrl' => true,
# 'showScriptName' => false,
# ],
# ]
#
# e.g. #app/admin/config/main.php
# 'homeUrl' => '/admin',
# ...
# 'components => [
# 'request' => [
# 'baseUrl' => '/admin',
# ],
# 'urlManager' => [
# 'enablePrettyUrl' => true,
# 'showScriptName' => false,
# ],
# ]
server {
set $project_root /home/yii/apps/yii-advanced;
set $fcgi_server unix:/opt/php/var/run/php5-fpm.sock;
charset utf-8;
client_max_body_size 128M;
listen 80;
server_name yii-application.local;
root $project_root/frontend/web;
index index.php;
access_log /home/yii/apps/yii-advanced/logs/access-backend.log;
error_log /home/yii/apps/yii-advanced/logs/error-backend.log;
location / {
try_files $uri $uri/ /index.php?$args;
}
location /admin {
index /web/index.php;
alias $project_root/admin/web;
try_files $uri $uri/ /web/index.php?$args;
location ~ ^/admin/.*\.php$ {
rewrite ^/admin/(.*)$ /web/$1;
fastcgi_pass $fcgi_server;
include fastcgi.conf;
}
}
location ~ ^/web/.*\.php$ {
internal;
root $project_root/admin;
fastcgi_pass $fcgi_server;
include fastcgi.conf;
}
location ~* \.php$ {
try_files $uri =404;
fastcgi_pass $fcgi_server;
include fastcgi.conf;
}
location ~* \.(htaccess|htpasswd|svn|git) {
deny all;
}
}
Try to specify the config Nginx :
I use the configuration for "Advanced" template
in the domain configuration file, specify the frontend for so:
listen frontend.site.loc:80; # for frontend
specify the backend domain:
listen backend.site.loc:80; # for backend
This guy has done a very good job of creating advanced app nginx config (with subdomain which IMHO is the best setup): https://gist.github.com/Kison/45ec9ce3c1ebf422cbd42bd5ce04d8e4

Resources