I have 2 nginx configurations. Both of them work well alone. One of them is for drupal (frontend) and one of them is the backend. At the end I would like to have mydomain.com/ = frontend & mydomain.com/backend = backend.
Unfortunately I don't know what I have to do to make this work.
Here both configs:
//Drupal
upstream fcp {
server unix:/var/run/php-fpm.sock;
}
server {
listen 80;
server_name www.example.com;
root /usr;
location / {
index index.php;
}
location ~ \.php$ {
fastcgi_pass fcp;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
include /usr/local/nginx/conf/fastcgi_params;
}
}
// ====== //
// Backend-Software
upstream backend{
server unix:/var/run/php-fpm.sock;
}
server {
[...]
server_name www.example.com;
root /usr/backend/wwwroot;
#Generic definition
location / {
index index.php;
try_files $uri $uri/ /index.php?route=$uri&$args;
}
#backend.net frontend controller (redirect these calls to PHP-FPM)
location ~ ^/index.php {
fastcgi_pass backend;
fastcgi_param SCRIPT_FILENAME /usr/backend/wwwroot$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
# Internal link to the files for X-Accel support
location /_files {
internal;
alias /usr/backend/_files/filesource/;
}
#Static Resources
location /wwwres/ {
expires 365d;
alias /usr/backend/wwwres/;
}
location ~ ^/wwwres/mod/([^/\.]*)/(.*)$ {
expires 365d;
alias /usr/backend/modules/$1/wwwres/$2;
}
location ~ ^/wwwres/vendor/([^/\.]*)/([^/\.]*)/(.*)$ {
expires 365d;
alias /usr/backend/vendor/$1/modules/$2/wwwres/$3;
}
location ~ ^/wwwres/theme/set_([^/\.]*)/(.*)$ {
expires 365d;
alias /usr/backend/_files/theme_set/$1/$2;
}
location ~ ^/wwwres/theme/([^/\.]*)/(.*)$ {
expires 365d;
alias /usr/backend/themes/$1/wwwres/$2;
}
location ~ ^/wwwres/vendor_theme/([^/\.]*)/([^/\.]*)/(.*)$ {
expires 365d;
alias /usr/backend/vendor/$1/themes/$2/wwwres/$3;
}
location ~ ^/_cache/(.*)$ {
expires 365d;
alias /usr/backend/_cache/$1;
}
#Error Pages
error_page 404 /static/error/404.php;
error_page 500 504 /static/error/500.php;
error_page 502 /static/error/502.html;
error_page 503 /static/error/503.php;
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
I think you can merge these configurations into one server section. The root in this section can be /usr (from first section - is this correct?) or /usr/backend/wwwroot. You should decide which will be the default (www.example.com): the /usr/index.php or the /usr/backend/wwwroot/index.php. As I see you want /usr/index.php so your root should be /usr. And should add
location /backend {
root /usr/backend;
...
}
The location /_files and "Static Resources" will right because you use alias in every section.
Summary:
http {
server_name example.com;
root /usr;
index index.php;
location /backend_uri {
alias /usr/backend; # if "backend_uri"=="backend" (and root is /usr) this section is unnecessary
}
location /_files {
# same as your post
}
# Static resources
# same as your post
}
Related
access link : http://142.93.60.127/phpmyadmin
my phpmyadmin.conf file is
server {
listen 80;
server_name 142.93.60.127;
location /phpmyadmin {
index index.php;
root /usr/share/phpMyAdmin;
}
## Images and static content is treated different
location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
access_log off;
expires 30d;
}
location ~ /\.ht {
deny all;
}
location ~ /(libraries|setup/frames|setup/libs) {
deny all;
return 404;
}
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/phpMyAdmin$fastcgi_script_name;
}
}
Usually when I have this problem it's a permissions issue.
Make sure you have the correct permissions on the /usr/share/phpMyAdmin directory and the files in it. The user that nginx is running on needs execute access to the directories and read access to the files.
Also try moving your "root" flag outside of the location flag:
server {
listen 80;
server_name 142.93.60.127;
root /usr/share/phpMyAdmin;
location / {
index index.php;
}
....
}
I solve this problem and write a blog about this
solution
I'm trying to install Typo3 on my CentOS server.
I want to run it with php7 and nginx.
If i do a index.php with phpinfo it works. after i change the index of to the index from Typo3 it doesent work anymore.
http://baddog.me/typo3/sysext/install/Start/typo3/sysext/install/Start/typo3/sysext/install/Start/typo3/sysext/install/Start/typo3/sysext/install/Start/typo3/sysext/install/Start/typo3/sysext/install/Start/typo3/sysext/install/Start/typo3/sysext/install/Start/typo3/sysext/install/Start/typo3/sysext/install/Start/typo3/sysext/install/Start/typo3/sysext/install/Start/typo3/sysext/install/Start/typo3/sysext/install/Start/typo3/sysext/install/Start/typo3/sysext/install/Start/typo3/sysext/install/Start/typo3/sysext/install/Start/typo3/sysext/install/Start/Install.php
my Nginx config:
server {
server_name baddog.me;
listen 80;
root /var/www/typo3/htdocs;
location ~* \.(?:jpg|css|js|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc|json|woff)$ {
expires 1M;
add_header Cache-Control "public";
}
error_page 500 501 502 503 504 /500.html;
location = /500 {
return 500;
}
location /500.html {
internal;
}
location /robots.txt {
}
location /favicon.ico {
}
location ~ \.png {
try_files $uri =404;
}
location / {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME /var/www/typo3/htdocs/index.php;
include fastcgi_params;
}
}
i changed some parameters in the php.ini.
Sorry for my bad english. I hope for help :) ty
Why do you hardcode the index.php as only file that is passed to PHP?
server {
listen *:8080;
root /var/www/html;
index index.php index.html index.htm;
server_name php7;
location / {
try_files $uri $uri/ =404;
}
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
include fastcgi_params;
fastcgi_pass unix:/var/run/php7-fpm.sock;
fastcgi_read_timeout 300;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
}
}
Check port (listen), root and server_name and adopt them as needed.
Also make sure that all files have the correct security label (selinux), thus run $ restorecon -rv /var/www/html.
I have installed a Magento extension to have a wordpress blog integrated with Magento.
Basically, the WP is in a subdirectory of the Magento root. I want to create multiple sites with subdirectories but I can't make it work due to the nginx configuration.
Wordpress is in his /wp subdirectory (http://example.com/wp/wp-admin/) and the others sites are accessible from http://example.com/wp/ca/wp-admin/ and http://example.com/wp/en/wp-admin/
Here is whats I got so far :
server
{
server_name dev.example.com;
access_log /var/log/nginx/example.access.log;-
error_log /var/log/nginx/example.error.log;
root /var/www/example;
location ^~ /wp {
index index.php index.html index.htm;
try_files $uri $uri/ /wp/index.php?q=$uri&$args;
# Multisite
if (!-e $request_filename) {
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
rewrite ^/wp(/[^/]+)?(/wp-.*) /wp$2 last;
rewrite ^/wp(/[^/]+)?(/.*\.php)$ /wp$2 last;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass 127.0.0.1:9000;
}
}
set $mage_developer true;
set $mage_code es;
set $mage_type store;
include snippets.d/magento-site;-
}
and in snippets.d/magento-site :
# Serve static pages directly,
# otherwise pass the URI to Magento's front handler
location / {
index index.php;
try_files $uri $uri/ #handler;
expires 30d;-
}
# Disable .htaccess and other hidden files
location /. {
return 404;
}
# Allow admins only to view export folder
location /var/export/ {
auth_basic "Restricted";
auth_basic_user_file htpasswd;
autoindex on;
}
# These locations would be hidden by .htaccess normally
location /app/ { deny all; }
location /includes/ { deny all; }
location /lib/ { deny all; }
location /media/downloadable/ { deny all; }
location /pkginfo/ { deny all; }
location /report/config.xml { deny all; }
location /var/ { deny all; }
# Magento uses a common front handler
location #handler {
rewrite / /index.php;
}
# Forward paths like /js/index.php/x.js to relevant handler
location ~ .php/ {
rewrite ^(.*.php)/ $1 last;
}
# Execute PHP scripts
location ~ .php$ {
# Catch 404s that try_files miss
if (!-e $request_filename) { rewrite / /index.php last; }
expires off;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_param MAGE_RUN_CODE $mage_code;
fastcgi_param MAGE_RUN_TYPE $mage_type;
fastcgi_ignore_client_abort on;
fastcgi_read_timeout 900s; # 15 minutes
}
Thanks for your help.
Wanted to pass along a full conf file for anyone who needs to configure this. Please keep in mind, many file paths are unique your your server configuration.
Please note, you'll need to adjust the following parameters based on file paths on your server:
server_name domain.com www.domain.com;
ssl_certificate /sslpath/domain.com.crt;
ssl_certificate_key /sslpath/domain.com.key;
root /webrootpath/domain.com;
rewrite ^/blogpath(.*) /blogpath/index.php?q=$1;
location ^~ /blogpath {
error_log /data/log/nginx/domain.com_error.log;
access_log /data/log/nginx/domain.com_access.log;
Here is the full nginx conf file:
server {
listen 80;
server_name domain.com www.domain.com;
rewrite ^ https://$server_name$request_uri? permanent;
}
server {
listen 443;
server_name domain.com www.domain.com;
ssl on;
ssl_certificate /sslpath/domain.com.crt;
ssl_certificate_key /sslpath/domain.com.key;
ssl_session_timeout 30m;
root /webrootpath/domain.com;
index index.php;
location / {
index index.html index.php;
try_files $uri $uri/ #handler;
expires 30d;
}
location #wp {
rewrite ^/blogpath(.*) /blogpath/index.php?q=$1;
}
location ^~ /blogpath {
root /webrootpath/domain.com;
index index.php index.html index.htm;
try_files $uri $uri/ #wp;
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass 127.0.0.1:9000;
}
}
location ~ ^/(app|includes|lib|media/downloadable|pkginfo|report/config.xml|var)/ { internal; }
location /var/export/ { internal; }
location /. { return 404; }
location #handler { rewrite / /index.php; }
location ~* .php/ { rewrite ^(.*.php)/ $1 last; }
location ~* .php$ {
if (!-e $request_filename) { rewrite / /index.php last; }
expires off;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param MAGE_RUN_CODE default;
fastcgi_param MAGE_RUN_TYPE store;
include fastcgi_params;
}
error_log /data/log/nginx/domain.com_error.log;
access_log /data/log/nginx/domain.com_access.log;
}
Well, in the end, it works passing all request to the blog to Apache and creating the site in the virtual hosts corresponding.
location ~ ^/blog {
proxy_pass http://apache:80;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_read_timeout 6000s;
}
If someone succeed to make it work with Nginx only, I'm looking forward to his answer :)
Why run Apache? Doesn't make sense to run 2 webservers.
Try adding this to your nginx conf.
location #wp {
rewrite ^/wp(.*) /wp/index.php?q=$1;
}
location ^~ /wp {
root /var/www/example;
index index.php index.html index.htm;
try_files $uri $uri/ #wp;
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass 127.0.0.1:9000;
}
}
I am trying to setup a Nginx / PHP-FPM server on my raspberry Pi (Debian) and I am having trouble getting the php to work correctly.
Text displayed on webpage: This Page is Temporarily Unavailble
I have checked the nginx logs and there are no errors being recorded.
This is my nginx.conf:
# Pi Nginx Config v0.1 10:53 30/01/2014
# NOTE: fastcgi is NOT php5-fpm
server {
listen 1080;
# server_name mysite.org;
charset utf-8;
access_log off;
root /var/www/cms;
index index.php;
location / {
try_files $uri $uri/ /index.php?id=$uri&$args;
}
location ~* /admin/.*\.php$ {
try_files $uri /admin/index.php?id=$uri&$args; # Try the admin index page
include /etc/nginx/fastcgi_params;
fastcgi_index index.php;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
location ~* \.php$ {
try_files $uri =404; # Try any .php files in root or throw a 404
include /etc/nginx/fastcgi_params;
fastcgi_index index.php;
# NOTE: You should have "cgi.fix_pathinfo = 0;" in /etc/php5/fpm/php.ini
# With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
expires 2h;
}
location ~* \.(?:ico|js|gif|jpg|png)$ {
expires 14d;
}
location ~* \.(htm|css|html)$ {
expires 2d;
}
# this blocks direct access to the XML files (but sitemap.xml) - that hold all the data
location ~* \.xml$ { deny all; }
location ~* \.xml\.bak$ { deny all; }
location = /sitemap.xml { allow all; }
# this prevents hidden files (beginning with a period) from being served
location ~ /\. { deny all; }
location ^~ /uploads/ {
if ($request_uri ~* \.php$) {return 403;}
}
}
I do not have enough experience to see anything wrong with this config. My server is on port 1080 and the server root is within the cms directory.
Any help would be greatly appreciated.
server {
listen 80;
server_name www.site.dk;
access_log /var/www/www.site.dk/logs/access.log;
error_log /var/www/www.site.dk/logs/error.log;
root /var/www/www.site.dk/;
location / {
index index.php index.html;
if (-f $request_filename) {
break;
}
if (!-f $request_filename) {
rewrite ^/(.+)$ /index.php last;
break;
}
}
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/www.site.dk$fastcgi_script_name;
}
}
I'm trying to get nginx to serve any physical file (css, images, js) without doing anything to it put let php handle all other requests. Everything that is not a physical file should be passed to php.
But it's not working, php is being executed, but calling a .css file is also passed to php as a request.
This will do the job
server {
listen 80;
server_name www.site.dk;
access_log /var/www/www.site.dk/logs/access.log;
error_log /var/www/www.site.dk/logs/error.log;
root /var/www/www.site.dk/;
index index.php index.html;
location / {
try_files $uri $uri/ #fastcgi;
}
location ~ .+\.php$ {
location ~ \..*/.*\.php$ { return 400; }
error_page 418 = #fastcgi;
return 418;
}
location #fastcgi {
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
...
}
}