I am creating server block in sites-available nginx. I have 2 server name it works fine if access to browser but in mobile it will show the i.p address and it will load the first app, I cannot load the my second app because If I dial in url mysecondsubdomain.mydomain.com it will redirect to i.p address and the first app will be serve.. I don't know why it behaves like this
updated : I noticed also in browser after few hours when I type mysecondsubdomain.mydomain.com i will be redirected to i.p adress and it will serve my first app
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/banking/public/;
index index.php index.html index.htm;
server_name banking.mydomain.com;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_pass unix:/var/run/php/php5.6-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
server {
listen 80;
listen [::]:80;
root /var/www/inventory/public/;
index index.php index.html index.htm;
server_name inventory.mydomain.com;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_pass unix:/var/run/php/php5.6-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Related
Please help me, I want to move the project rest api (Slim 4 use Design Pattern) from apache to nginx, but I haven't found a solution to this problem, how to convert .htaccess to nginx server configuration, the error I found is always 404 (Slim / Middleware / RoutingMiddleware.php)
thank you for your help
this server config nginx
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.html index.php index.htm index.nginx-debian.html;
autoindex off;
server_name _;
location / {
try_files $uri /index.php$is_args$args;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_index index.php;
}
location /FjbBaseApi {
index index.php index.html index.htm;
try_files $uri $uri/ /FjbBaseApi/public/index.php;
rewrite ^/$ /public/ break;
rewrite ^(.*)$ /public/$1 break;
}
location ~ /\.ht {
deny all;
}
}
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.
I want to install my vps to develop multiple websites at the same time.
My root directory structure:
/var/www/html/web1;
/var/www/html/web2;
/var/www/html/wordpress1;
/var/www/html/wordpress1;
/var/www/html/drupal1;
/var/www/html/drupal2;
I want to link to the website http://123.123.123.123/drupal1 and 123.123.123.123 is the IP of the VPS.
Now whenever I add a website I have to edit the config file. Is there a way to install it for every page?
Here is my nginx config:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.html index.htm index.nginx-debian.html index.php;
server_name _;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location #sub_rewrite {
rewrite ^/drupal1/(.*)$ /drupal1/index.php?$1;
}
location /drupal1/ {
try_files $uri #sub_rewrite;
}
}
Thanks everyone!
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 ?
I am trying to add a subdomain along side my existing website setup.
I have added the following server block to my nginx configuration located at /etc/nginx/sites-available/default.
server {
listen 80;
server_name stats.website.org;
root /var/www/piwik;
index index.php index.html;
location / {
try_files $uri $uri/ =404;
}
}
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/html/existing_website/public;
index index.php index.html;
server_name website.org;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_split_path_info ^(.+\.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;
}
}
I am getting a ERR_NAME_NOT_RESOLVED error when I try stats.website.org.
Can anyone advise where I am going wrong.
Thanks in advance.