I have a html/jQuery website(mysite.com) with a wordpress blog(mysite.com/blog). Html site(mysite.com) is hosted on ec2 A instance(and working fine) and blog(mysite.com/blog) is hosted on ec2 B instance.
The blog(WordPress) is loading the HTML page but all the CSS/JS and images hosted on ec2 B are not loading and ending up 404. Even if I try to access the CSS in the browser, it ends up 404, although the file exists on the server.
I tried to tweak the Nginx config but couldn't able to resolve the issue. Any help would be much appreciated.
My nginx config
server {
listen 80;
server_name mysite.com;
root /opt/mysite-blog;
index index.php index.html;
access_log /var/log/nginx/mysite_blog-access.log;
error_log /var/log/nginx/mysite_blog-error.log error;
keepalive_timeout 70;
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location /blog {
index index.php;
try_files $uri $uri/ /index.php?q=$uri&$args;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass backend_php;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc|svg|woff|woff2|ttf)\$ {
expires 30d;
proxy_cache staticcache;
proxy_cache_valid 200 30d;
add_header Cache-Control public;
access_log /dev/null;
}
location ~* \.(?:css|js)\$ {
expires 1d;
add_header Cache-Control public;
access_log /dev/null;
}
location ~ /\.ht {
deny all;
}
}
Resolved the issue by making the following changes
server_name mysite.com;
root /opt/mysite;
location /blog {
index index.php;
alias /opt/mysite-blog;
try_files $uri $uri/ /index.php?$args;
}
if (!-e $request_filename) {
rewrite ^.*$ /index.php last;
}
Related
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.
We're running a Wordpress site on a Nginx server, I am now trying to install Piwik there in the /stats folder.
This is the default Nginx configuration that came with the install, I added the "/stats" block myself, but it doesn't work - it gets rendered by WordPress whenever I go to mysite.com/stats instead of going to that folder.
Desired behavior would be that the /stats subdirectory (and all files and directories in it) is just parsed by PHP as would be on a default install without Nginx rules
Any clue what I'm missing?
server_name _;
port_in_redirect off;
client_header_buffer_size 4k;
client_body_buffer_size 128k;
client_max_body_size 16m;
root /var/www/html;
index index.html index.php;
charset utf-8;
log_not_found off;
gzip_static on;
gzip_types text/css application/javascript text/xml;
gzip_vary on;
gzip on;
# redirect server error pages to the static page /50x.html
#
error_page 500 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location #rewrite {
rewrite ^.*$ /index.php?$args;
}
error_page 404 #rewrite;
# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
# WP Multisite rewrites
rewrite /([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) /$2 last;
rewrite /([_0-9a-zA-Z-]+/)?(.*\.php)$ /$2 last;
location / {
try_files $uri $uri.gz $uri/ #rewrite;
}
location ~ \.sql$ {
rewrite ^.*$ /index.php?$args;
}
# We do not want to run php from wp uploads
location ~* /(?:uploads|files)/.*\.php$ {
rewrite ^.*$ /index.php?$args;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors off;
}
location /stats {
try_files $uri $uri/ /index.php?$args;
index index.php;
}
location = /favicon.ico {
access_log off;
expires 2w;
add_header Cache-Control public;
try_files $uri #rewrite;
}
location ~* \.(js|css|jpg|jpeg|png|gif|ico|woff|woff2|ttf|otf|eot|pdf|xml|mp4|ogg|mp3|mov|wmv|avi|cur|rtf|txt|swf)$ {
add_header Cache-Control public;
add_header Access-Control-Allow-Origin *;
expires 2w;
try_files $uri $uri.gz;
}
The rules for multi-site WordPress, particularly this one: rewrite /([_0-9a-zA-Z-]+/)?(.*\.php)$ /$2 last; will redirect any /stats/index.php URI back to WordPress's /index.php.
If you are not using a multi-site WordPress, you can safely delete the redundant rewrite rules.
If you are using a multi-site WordPress, some redesign is required.
I want to run php-fpm via nginx, but for different locations I want to specify different roots:
for path:
http://localhost/ -> /usr/share/nginx/html
http://localhost/pma -> /var/www/default/phpMyAdmin/
http://localhost/pga -> /var/www/default/phpPgAdmin/
My configuration doesn't work properly:
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
try_files $uri =404;
index index.php index.html;
location / {
}
# redirect server error pages to the static page /40x.html
#
error_page 404 /404.html;
location = /40x.html {
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
location /pma {
root /var/www/default/phpMyAdmin;
try_files $uri =404;
index index.html index.php;
}
location ~ \.php$ {
try_files $uri =404;
include fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
I always receive 404 error.
When you set location /pma and root /var/www/default/phpMyAdmin request http://server/pma/index.php was search file /var/www/default/phpMyAdmin/pma/index.php.
Use something like this:
location /pma/ {
rewrite /pma/ /phpMyAdmin/ last;
}
location /phpMyAdmin {
root /var/www/default/
try_files $uri =404;
index index.html index.php;
}
or rename /var/www/default/phpMyAdmin to /var/www/default/pma and change config to
location /pma {
root /var/www/default/
try_files $uri =404;
index index.html index.php;
}
Here is code that i'm using in nginx.
location /phpMyAdmin {
root /var/www/default;
index index.php index.html;
location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/default$fastcgi_script_name;
include fastcgi_params;
}
}
I'm writing an application in fuelphp. On my local vagrant box everything works perfectly. I've create a sub domain from my main server for the development box, forwarding to the IP of a digital ocean droplet, installed nginx, php5-fpm and all the other bits needed to get fuel working and the home page works properly but when I try to navigate to any other area of the site I get this error in the error.log
2013/12/06 22:54:46 [error] 10177#0: *2 rewrite or internal redirection cycle while internally redirecting to "/index.html", client: xxx.xxx.xxx.xxx, server: xxx.xxxxxxx.com, request: "GET /region HTTP/1.1", host: "xxx.xxxxxxx.com"
the .conf for the virtual host is :
server {
root /usr/share/nginx/html/fuel_app/public;
server_name xxx.xxxxxxx.com;
location / {
index index.php index.html index.htm;
try_files $uri $uri/ /index.html;
}
error_page 404 /404.html;
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# root /usr/share/nginx/html/fuel_app/public;
# }
location #handler {
rewrite / /index.php;
}
location ~ .php/ {
rewrite ^(.*.php)/ $1 last;
}
location ~ .php$ {
if (!-e $request_filename) { rewrite / /index.php last; }
expires off;
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
What am I missing here?
i'm not an expert but this is the configuration that we use in production with nginx and php-fpm:
server {
listen 80;
server_name www.yourserver.com
root /var/www/YOURSITE/public; # whatever is yours
index index.php index.html index.htm;
location / {
try_files $uri $uri/ #handler;
expires 30d;
}
location #handler {
rewrite ^ /index.php?/$request_uri;
}
location ~ ^/index.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PHP_VALUE open_basedir="/var/www/YOURSITE/:/usr/share:/tmp/";
include fastcgi_params;
}
location ~ \.php$ {
deny all;
}
location ~* ^/(modules|application|system) {
return 403;
}
error_page 404 /index.php;
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
access_log /var/log/nginx/YOURSITE.it-access.log;
error_log /var/log/nginx/YOURSITE.it-error.log;
}
We have some different settings and mabye it's one of them. Another thing that I'll check is config.php. In many project we have to set base_url manually and maybe you also have to do it or you have settled it and you have to change it for your production configuration
I'm using Wordpress as root of my website and Invision Power Boards as forum.
http://localhost -> Wordpress
http://localhost/forum -> IPB
I have removed "index.php" from Wordpress URLs successfully with Nginx-rewrite however when I try to use SEO Friendly URLs on IPB, nginx simply returns to Wordpress' 404 page.
My configuration is like this:
#This removes "index.php" from Wordpress URLs
location / {
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?q=$uri&$args;
}
Then I follow this link to modify my nginx conf file in order to be able to use SEO friendly URLs of IPB: http://www.devcu.com/forums/topic/262-furl-friendly-urls-with-ipb-and-nginx/
#This part is to be able to use IPB SEO
location /forum/ {
index index.php;
try_files $uri $uri/ /forum/index.php?$uri&$args;
rewrite ^ /index.php? last;
}
When I click a link on my forum (for example: http://localhost/forum/index.php/forum/51-sport/) nginx simply redirects me to (http://localhost/forum/forum/51-sport/) which displays Wordpress 404 error page.
I have very little knowledge about regex so any help would be appreciated.
This is my whole conf file after modifications, little messy I accept that.
server {
listen 80; ## listen for ipv4; this line is default and implied
#listen [::]:80 default ipv6only=on; ## listen for ipv6
root /home/user_name/public_html;
access_log /var/log/nginx/a/access.log;
error_log /var/log/nginx/a/error.log
server_name localhost;
server_tokens off;
location / {
try_files $uri $uri/ #wordpress;
}
location #wordpress {
fastcgi_pass php-fpm;
fastcgi_param SCRIPT_FILENAME /home/user_name/public_html$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_NAME /index.php;
}
location /forum {
try_files $uri $uri/ try_files $uri $uri/ /forum/index.php?q=$uri;
}
location /forum/ {
try_files $uri $uri/ try_files $uri $uri/ /forum/index.php?q=$uri;
}
#location / {
#index index.php index.html index.htm;
#try_files $uri $uri/ /index.php?q=$uri&$args;
#}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~ \.php$ {
fastcgi_split_path_info ^(/)(/.*)$;
}
# Add trailing slash to */wp-admin and */forum requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9001
#location ~ \.php$ {
# fastcgi_split_path_info ^(/)(/.*)$;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /home/user_name/public_html$fastcgi_script_name;
# fastcgi_param PATH_INFO $fastcgi_script_name;
# include /etc/nginx/fastcgi_params;
#REMOVE THIS
#fastcgi_read_timeout 60000;
#fastcgi_send_timeout 6000;
#}
}
Since the last post, I have played with IPB's SEO configurations and I managed to remove "index.php" from URLs. It doesn't effect the result of course. But it seems that location / decides what to do and therefore link is being considered as a Wordpress permalink.
EDIT - Solution
# Upstream to abstract backend connection(s) for php
upstream php {
# server unix:/tmp/php-cgi.socket;
server 127.0.0.1:9001;
}
server {
## Your website name goes here.
server_name localhost;
## Your only path reference.
root /home/username/public_html;
## This should be in your http block and if it is, it's not needed here.
index index.php;
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location / {
# This is cool because no php is touched for static content
try_files $uri $uri/ /index.php;
}
location /forum {
try_files $uri $uri/ /forum/index.php;
rewrite ^ /forum/index.php? break;
}
location ~ ^/forum/index.php {
if ($args != "") {
rewrite ^ http://www.google.com/ permanent;
}
try_files $uri $uri/ /forum/index.php;
rewrite ^ /forum/index.php? last;
}
location /forum/admin/ {
try_files $uri $uri/ /forum/admin/index.php;
rewrite ^ /forum/admin/index.php? last;
}
location ~ \.php$ {
#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
include /etc/nginx/fastcgi_params;
fastcgi_intercept_errors on;
fastcgi_pass php;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
}
I'm too using wordpress and ipb on nginx, now configuring, i added wordpress permalink to ipb config and turn on seo Rewrite URLs, Force Friendly URLs
location / {
try_files $uri $uri/ /index.php?$args;
}
it worked for me