only see 'welcome to nginx' when accessing site from public ip address - php

When I access my wordpress site via localhost or the local LAN address, everything works properly.
But when I access it from outside, like this: http://123.123.123/ (where 123.123.123 is my public ip) I only get the Welcome to nginx page. However, if I access http://123.123.123/wordpress, I do get a wordpress page.
What could be wrong?
The following is my nginx configuration:
server {
listen 80;
root /var/www/;
index index.php index.html index.htm;
server_name 123.123.123.123;
location / {
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/www;
}
# pass the PHP scripts to FastCGI server listening on a UNIX socket
location ~ \.php$ {
#fastcgi_pass 127.0.0.1:9000;
# With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
How do I get started debugging this?

Since your try_files has $uri as first argument, you will hit the index.html in your /var/www and that will satisfy that, so if you put the php-argument first, or go to:
http://123.123.123.123/index.php
you should see your wordpress site.

Related

Sample PHP page on localhost shows a blank page

I follow this guide to setup a sample WordPress site on my Linux machine. The packages are changed to the newer php7.2-gd, php7.2-curl, and libssh2-php. My /etc/nginx/sites-available/davewordpress file is as follow:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/wordpress;
index index.php index.html index.htm;
server_name localhost;
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/php/php7.2-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
After creating the davewordpress link in /etc/nginx/sites-enabled and restarting nginx and php7.2-fpm, my localhost gives a blank page. What have I done wrong?
OK, I run into this link while searching for the solution, and it really helps by pointing to the location ~ \.php$ block. I comment out two lines and have it working. That blocks now looks like this:
location ~ \.php$ {
#try_files $uri =404;
include snippets/fastcgi-php.conf;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
#fastcgi_index index.php;
include fastcgi_params;
}
Using sudo nginx -t, the first line reports this problem:
"try_files" directive is duplicate in /etc/nginx/snippets/fastcgi-php.conf:5
The second line reports this problem:
"fastcgi_index" directive is duplicate in /etc/nginx/sites-enabled/u1804wordpress:27
Glad to finally figure it out. I understand the first error. However, can anybody explain to me the second one?

nginx + codeigniter configuration not working on CentOS 7?

I am new on nginx and try to find the issue on StackOverflow but not found the exact one on forums.
After successful installation of nginx, MySQL and php-fpm I test the php.info that was working fine.
I am moving the CodeIgniter project to the nginx from apache server. I edit the nginx.conf file that has code
server {
listen 80;
server_name 173.249.40.xxx;
# note that these lines are originally from the "location /" block
root /usr/share/nginx/html/ci;
index index.html index.htm index.php;
location /ci {
try_files $uri $uri/ /index.php;
}
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;
}
}
it was working fine for php.info like my path is http://173.249.40.xxx/ci/info.php but not working for CodeIgniter controller name like http://173.249.40.xxx/ci/index.php/Welcome when called. I try from
https://www.nginx.com/resources/wiki/start/topics/recipes/codeigniter/#
for CodeIgniter application but it also not work for me.
The CodeIgniter application path is '/usr/share/nginx/html/ci/;'
Please suggest me something. how can I fix it?
The codeigniter has it's own routing mechanism so in order to work you need from web server to pass everything you can't find to the index.php not to toss 404 messages.
So try to change your location / {...} block to the following:
location /ci/ {
# Check if a file or directory index file exists, else route it to index.php.
try_files $uri $uri/ /ci/index.php;
}
The above it's taken from the link in your question.

Error on Installing Wordpress on Nginx

I'm trying to install a wordpress site in a Linux VPS with LEMP Setup. So far I've done setting up the wordpress files and setting ownership for nginx user/group on the WP directory/files, but when I go to the address to access the installation page for WP (https://domain.tld/wp-admin/install.php), I end up with a php file download instead.
Here's my virtual host configuration for the WP site:
server {
listen 80;
server_name domain.tld;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
ssl on;
ssl_certificate /directory/to/crt;
ssl_certificate_key /directory/to/key;
server_name domain.tld;
root /var/www/html/domain.tld;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
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_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index index.php;
include fastcgi_params;
}
}
EDIT: I tried it in Firefox, and it's acting differently than in Chrome. The install.php page instead ends up in an error page like this:
An error occurred.
Sorry, the page you are looking for is currently unavailable.
Please try again later.
If you are the system administrator of this resource then you should check the > error log for details.
Faithfully yours, nginx.
I got it working now. The error was on the virtual host's *.conf file. I got the directory for php-fpm sock wrong. So that was the reason the php is not working on the site, and instead just downloads the install.php file, and domain is ending up in error.
fastcgi_pass unix:/var/run/php5-fpm.sock; <---- I just got the directory wrong on this one.
Maybe just u forget to start your php-fpm
cd /usr/local/php7-chanxiao/etc/
../sbin/php-fpm

Nginx conf issue with IP restriction & 403.html - it downloads index.php & 403.html instead of processing

I've attached my Nginx conf file for my default site which runs on Ubuntu.
What I'm trying to achieve is the following:
Main directory is /usr/share/nginx/www with the default file index.php
Restricting IP addresses for now until launch so only my IP's can view the site
For everyone else that attempts to visit the site, deny them, but display a custom 403 page which is 403.html which is sitting in the /usr/share/nginx/www main directory
What happens though is when I visit the site from a different IP address (one that is denied access) it will load the 403.html page but download a file called "download". If I visit example.com OR example.com/index.php it will download an index.php file.
Something isn't configured correctly but unsure what it is.
server {
listen 80;
root /usr/share/nginx/www;
index index.php;
server_name example.com;
location / {
try_files $uri $uri/ /index.php;
# restrict IP's
allow 123.456.789.0;
allow 123.456.789.1;
deny all;
}
location = /403.html {
root /usr/share/nginx/www;
allow all;
}
error_page 404 /404.html;
error_page 403 /403.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/www;
# root /var/www;
}
# pass the PHP scripts to FastCGI server listening on the php-fpm socket
location ~ \.php$ {
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;
}
}

Nginx Wordpress Configuration, PHP file in theme directory is not passed to FastCGI

I am new to NGINX configs so bear with me. Below is my configuration which works fine for the whole site:
server {
listen ...;
server_name funkyoslo.no;
#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;
location / {
root /usr/share/nginx/funkyoslo.webbr.org/html;
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?q=$uri&$args;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/funkyoslo.webbr.org/html/;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/funkyoslo.webbr.org/html/$fastcgi_script_name;
include fastcgi_params;
}
}
However, I am trying to load the file /wp-content/themes/funkyoslo/load-songs.php and it's giving me a 500 internal server error. I've checked the error logs and evidently the file isn't passed to FastCGI at all.
I tried adding the following block to no avail:
location ~ .*/wp-content/themes/funkyoslo/.*\.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/funkyoslo.webbr.org/html/wp-content/themes/funkyoslo/$fastcgi_script_name;
include fastcgi_params;
}
Any help is greatly appreciated!
Look I don't know what's wrong with your config but try this and hopefully it should work, this is the minimal config.
Notes:
Removed the index to the server block level, check link to know why
Removed root to server block level, check link to know why
Removed all extra config from the php block level, by trials I realised that I only need those two I've written.
Added http:// to fastcgi_pass, I don't know if it's really required but I got used to writting it this way.
Edit: Ok apparently I don't need the http://, I just checked.
-
server {
listen 80;
server_name funkyoslo.no;
root /usr/share/nginx/funkyoslo.webbr.org/html;
error_page 500 502 503 504 /50x.html;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php$request_uri;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass http://127.0.0.1:9000;
}
}

Categories