My domain registrar's DNS hits my server and gets the nginx default page, so that's properly configured
I copied an nginx vhost that is currently working, changed the server_name and the name of the conf file and nothing else.
Diff:
diff 701sm.club.conf drz400.info.conf
3c3
< server_name www.701sm.club 701sm.club;
---
> server_name www.drz400.info drz400.info;
then I restarted nginx.
Here is the entire non-functioning vhost:
server {
listen 80;
server_name www.701sm.club 701sm.club;
index index.php index.html index.htm;
access_log /var/www/drz400.info/logs/access.log;
error_log /var/www/drz400.info/logs/error.log;
location / {
root /var/www/drz400.info/production;
}
location ~ \.php$ {
root /var/www/drz400.info/production;
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;
}
}
Both sites should hit my .../production/index.html, but only one does. What could be wrong here?
Please try the following code,
server {
listen 80;
server_name www.701sm.club 701sm.club;
index index.php index.html index.htm;
access_log /var/www/drz400.info/logs/access.log;
error_log /var/www/drz400.info/logs/error.log;
root /var/www/drz400.info/production;
location / {
try_files $uri /index.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;
}
}
Just got curious about your log directive, you point out the log to /var/www/drz400.info/logs/error.log while your domain was www.701sm.club. If you access www.701sm.club, is there any error on your error.log ?
And what type of error was occurred ?
Related
I am trying to have 2 websites running on the same adress,
I want everything request on my.website.com/test_slim and every my.website.com/test_slim/anything/following to be directed on /var/www/html/test_slim/src/public/index.php.
I want everything else (my.website.com/, my.website.com/foo, my.website.com/bar/baz ...) to be served as normal PHP files in /var/www/html/whatever/file/according/to/url/index.php
Fow now, this are my server configurations :
In /etc/nginx/site-enabled/my-default
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name _;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
}
In /etc/nginx/sites-enabled/test_slim
server {
listen 80;
server_name _;
index index.php;
error_log /var/www/html/test_slim/error.log;
access_log /var/www/html/test_slim/access.log;
root /var/www/html/test_slim/src/public;
location /test_slim/ {
try_files $uri /index.php$is_args$args;
}
location ~ \.php {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi.conf;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_index index.php;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
}
}
But what I actually get is :
Request on localhost/ execute /var/www/html/index.html as wanted.
Request on localhost/toto execute /var/www/html/toto/index.html as wanted.
Request on localhost/test_slim downloads the /var/www/html/test_slim/src/public/index.pxp
Request on localhost/test_slim/hello returns us a Nginx error page (404 if hello folder doesn't exist, 403 if it does).
Request on localhost/test_slim/src/public/ exectute the /var/www/html/test_slim/src/public/index.php file.
So here's my server block
server {
listen 80;
server_name domain.tld;
root /var/www/domain.tld/html;
index index.php index.html index.htm;
location / {
}
location /phpmyadmin {
alias /var/www/phpmyadmin;
}
location /nginx_status {
stub_status on;
access_log off;
}
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;
}
}
browsing http://domain.tld/index.php works fine the only problem im encountering is browsing http://domain.tld/phpmyadmin/. It returns 404 yet the folder /var/www/phpmyadmin exist on the server. Viewing /var/log/nginx/error.log, no error is being logged there yet the access to it is logged in /var/log/nginx/access.log. What could be the problem here?
The problem is that phpmyadmin is a PHP application and your location ~ \.php$ block does not point to the correct document root.
You need to construct two PHP locations with different document roots.
If phpmyadmin is located at /var/www/phpmyadmin, you do not need an alias directive, as a root directive will be more efficient. See this document.
server {
listen 80;
server_name domain.tld;
root /var/www/domain.tld/html;
index index.php index.html index.htm;
location / {
}
location /nginx_status {
stub_status on;
access_log off;
}
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;
}
location ^~ /phpmyadmin {
root /var/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;
}
}
}
The location ^~ /phpmyadmin is a prefix location that takes precedence over the regex location normally used to process .php files. It contains a location ~ \.php$ block which inherits a value of /var/www for the document root.
It is advisable to include fastcgi_params before defining other fastcgi_param parameters otherwise your custom values may be silently overwritten.
See this document for more.
I'm getting a 404 error after install phpMyAdmin using Digital Ocean's guide. I have multiple domains setup on Ubuntu running nginx. There is a phpmyadmin directory within /var/www/. The only difference from the guide was the following command:
sudo ln -s /usr/share/phpmyadmin/ /var/www
Do I need to add server block possibly? Since I have multiple domains, each of them has a separate configuration file.
Sample config file:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/domain1.com/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name MY_IP_ADDRESS;
location / {
try_files $uri $uri/ =404;
}
location /phpmyadmin {
root /var/www/;
index index.php index.html;
}
location ~ \.php$ {
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
include fastcgi_params;
try_files $uri /index.php;
}
location ~ /\.ht {
deny all;
}
}
I'm not great at server administration. Any suggestions?
Define this server block it worked for me.
A basic configuration for phpmyadmin in you case.As you have created a symbolic link in /var/www.
sudo ln -s /usr/share/phpmyadmin/ /var/www
server {
listen 80;
server_name website.in www.website.in;
autoindex on;
location /phpmyadmin {
root /var/www/;
index index.php index.html;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
include fastcgi_params;
try_files $uri $uri/ /index.php;
}
}
location / {
root /var/www/your/path;
index index.php index.html;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
include fastcgi_params;
try_files $uri $uri/ /index.php;
}
}
}
So here's my server block
server {
listen 80;
server_name domain.tld;
root /var/www/domain.tld/html;
index index.php index.html index.htm;
location / {
}
location /phpmyadmin {
alias /var/www/phpmyadmin;
}
location /nginx_status {
stub_status on;
access_log off;
}
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;
}
}
browsing http://domain.tld/index.php works fine the only problem im encountering is browsing http://domain.tld/phpmyadmin/. It returns 404 yet the folder /var/www/phpmyadmin exist on the server. Viewing /var/log/nginx/error.log, no error is being logged there yet the access to it is logged in /var/log/nginx/access.log. What could be the problem here?
The problem is that phpmyadmin is a PHP application and your location ~ \.php$ block does not point to the correct document root.
You need to construct two PHP locations with different document roots.
If phpmyadmin is located at /var/www/phpmyadmin, you do not need an alias directive, as a root directive will be more efficient. See this document.
server {
listen 80;
server_name domain.tld;
root /var/www/domain.tld/html;
index index.php index.html index.htm;
location / {
}
location /nginx_status {
stub_status on;
access_log off;
}
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;
}
location ^~ /phpmyadmin {
root /var/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;
}
}
}
The location ^~ /phpmyadmin is a prefix location that takes precedence over the regex location normally used to process .php files. It contains a location ~ \.php$ block which inherits a value of /var/www for the document root.
It is advisable to include fastcgi_params before defining other fastcgi_param parameters otherwise your custom values may be silently overwritten.
See this document for more.
I have an A Name domain setup on Nginx, I also have wildcard DNS setup on Digital Ocean.
I would like my main domain to point to where it is: /usr/share/nginx/html/mission13.io
I would then like all the wildcard domains to point to their respective folders:
/usr/share/nginx/html/sub1.mission13.io
/usr/share/nginx/html/sub2.mission13.io
/usr/share/nginx/html/sub3.mission13.io
Here is what I have, but I am not sure what to do to get them to point to the proper location. What can I change to do that?
server{
listen 80;
root /usr/share/nginx/html/mission13.io;
index index.php index.html index.htm;
server_name mission13.io www.mission13.io *.mission13.io;
location / {
try_files $uri $uri/ /index.html;
}
include /usr/share/nginx/conf/mission13.io.conf;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Another way please change server name to _ then it will search folder with the host name inside root /usr/share/nginx/html/ directory.so,your directory looks clean
server{
listen 80;
root /usr/share/nginx/html;
index index.php index.html index.htm;
server_name _;
location / {
try_files $uri $uri/ /index.html;
}
include /usr/share/nginx/conf/mission13.io.conf;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Got it!
I need to use $http_host like so:
root /usr/share/nginx/html/$http_host;