I am trying to run Wordpress on my NGinx server, however I think that something is wrong because the index.php file keeps downloading rather than being run.
here is my sites-available:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/html;
index index.php index.html index.htm;
server_name your_domain.com;
location / {
# try_files $uri $uri/ =404;
try_files $uri $uri/ /index.php?q=$uri&$args;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php7.1-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
I checked to make sure that I had php7.1-fpm running and that my nginx was running as well. Both checked out to be just fine.
What am I missing?
Thanks
This link solved my problem. I was missing some packages that wordpress needed. After going through that guide everything worked
Related
I have two sites in my centos 7 VPS. One is laravel 5.6 (let say, def.com) and the other is static html site (let say, abc.com).
The html site is running smoothly with this config:
sites-available/abc.com.conf
server {
listen 80;
server_name server_name abc.com www.abc.com;
# note that these lines are originally from the "location /" block
#root /var/www/abc.com/html;
#index index.php index.html index.htm;
location / {
root /var/www/abc.com/html;
index index.php index.html index.htm;
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
But when I am adjust the config for laravel project, like below, it come with 404
sites-available/def.com.conf
server {
listen 80;
server_name server_name def.com www.def.com;
# note that these lines are originally from the "location /" block
#root /var/www/def.com/public;
#index index.php index.html index.htm;
location / {
root /var/www/def.com/public;
index index.php index.html index.htm;
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
I am using this guide https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-server-blocks-on-centos-7
replace this
try_files $uri $uri/ =404;
with
try_files $uri $uri/ /index.php$is_args$args;
after that run
sudo service nginx restart
Try to put the root and index directives in the server block (outside of the location block), and modify the try files to: try_files $uri $uri/ /index.php?$query_string;
Also you have the server_name two times on the 3rd line.
You can find a comprehensive guide here: https://www.digitalocean.com/community/tutorials/how-to-deploy-a-laravel-application-with-nginx-on-ubuntu-16-04
I have a LEMP server and I'm looking to install RespondCMS (http://respondcms.com/documentation/install-on-digital-ocean). I'm running into some difficulties with the mod_rewrite section for an API. I've tried several iterations but have been unable to get it to show an "API works" message that indicates the PHP app is working. I get a 404. Thus far, I have settled on the following set-up in my /etc/nginx/sites-enabled/. I'm thinking it's not accessing the /api folder correctly. Any help in understanding how it's all interacting and how to make it work is appreciated.
app.domain.com
server {
listen 80;
server_name app.domain.com;
root /srv/www/domain_app/app;
index index.php index.html index.htm;
access_log /var/log/nginx/respond.access.log;
error_log /var/log/nginx/respond.error.log;
location /api/ {
try_files $uri $uri/ /api/dispatch.php$args;
}
location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /srv/www;
}
location ~ \.php$ {
try_files $uri =404;
include fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
domain.com
server {
listen 80 default_server;
root /srv/www/html;
index index.php index.html index.htm;
server_name domain.com;
location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
The URL http://app.domain.com/api/dispatch.php is processed by the location ~ \.(hh|php)$ block. And that block seems to be configured (reasonably) correctly.
You should move include fastcgi_params; above any fastcgi_param directive to avoid the latter being inadvertently overridden. And the fastcgi_index directive is redundant in this context.
Both the location / and location /api/ blocks have issues. The alias directive is unnecessary and wrong. All three locations inherit their root from the outer server block. You should delete both alias directives.
In your try_files $uri $uri/ $uri.php /api/dispatch.php$args; statement, the $uri.php element will cause the PHP file to be downloaded rather than executed. Only the last element of a try_files directive can take an action that is not processed within the same location block. If you really need to execute extension-less PHP URIs and have a default PHP URI too, you will probably need to use a named location.
A useful resource for all nginx directives is here.
So while following this tutorial to implement two website on my NginX server.
Lin to the Website
I created two folder as follow
sudo nano /etc/nginx/sites-available/ideconnect.com
my file look like this
server {
listen 80;
listen [::]:80;
root /var/www/ideconnect.com/html;
index index.php index.html index.htm;
# Make site accessible from http://localhost/
server_name ide-portal.com www.ide-portal.com;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
Then the other website
sudo nano /etc/nginx/sites-available/iclock.com
server {
listen 80 ;
listen [::]:80;
root /var/www/iclock.com/html;
index index.php index.html index.htm;
# Make site accessible from http://localhost/
server_name iclock.in www.iclock.in;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
Also I have created the SYMLINKS properly
sudo ln -s /etc/nginx/sites-available/ideconnect.com /etc/nginx/sites-enabled/ideconnect.com
sudo ln -s /etc/nginx/sites-available/iclock.com /etc/nginx/sites-enabled/iclock.com
After this when I got to my ip address I can only see the default Nginx Page also now the info.php configuration page is also not visible.
Any help would be appreciated
Thanks
There are two things you can check to begin with:
Did you restart nginx?
Are you sure your nginx configuration is set up to include .com files? I think the default is to include all .conf files. You can check that in your nginx configuration file and then adapt that or modify the extension of your symlinks.
I followed a guide from here to install wordpress on my ubuntu server. Upon entering the url http://mydomain.com loads me the front page.
server {
listen 80 default_server;
root /var/www/wordpress;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
I want to load wordpress from my subdomain i.e., http://mydomain.com/wordpress. I went on to modify the location but it can't load properly (it still looks for files under http://mydomain.com).
root /var/www;
index index.php index.html index.htm;
location /wordpress {
try_files $uri $uri/ /index.php?q=$uri&$args;
}
or
location /{
try_files $uri $uri/ /wordpress/index.php?q=$uri&$args;
}
How do I fix this? thanks
Your wordpress looking for his files in root directory. /
So you need to tell him, to search his files in the right directory. /wordpress/
There are two ways.
Better: to change the path using wordpress config file for rewriting resources path
from
/css/*, /* etc
to
/wordpress/css/*, /wordpress/* and so on.
Worst: to redirect your wordpress resources to root directory. Something like this:
location ~ ^/images/(.*)$ {
try_files $uri /wordpress/images/$uri =404;
access_log off;
}
I tried to run the yii application on my vps which is installed with nginx as a server. but when I access my domain: www.domain.com, pages appear fine but if one link is always accessed 404 not found error. Is there something wrong with my nginx settings?
My nginx configuration :
server {
listen 80;
server_name www.mydomain.com;
location / {
root /usr/share/nginx/html;
index index.php index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
below the index line add this line
try_files $uri $uri/ /index.php$request_uri;