my server ip is 103.107.122.13 and port:5680.
i want two application suppose 103.107.122.13:5680/test1 then it enter var/www/html/test1 website and 103.107.122.13:5680/test2 it enter var/www/html/test2 website using virtual host. please tell me how can i manage this need also any change in nginx.conf file .
if anyone know please help me to solve this problem .
I already write two file inside site-available folder test1.conf file
server {
listen 80;
location /test1{
root /var/www/html/test1;
index index.php;
try_files $uri $uri/ =404;
}
}
and test2.conf file
server {
listen 80;
location /test2{
root /var/www/html/test2;
index index.php;
try_files $uri $uri/ =404;
}
}
Why different files? You should put this to /etc/nginx/nginx.conf:
http {
server {
listen 80;
location /test1{
root /var/www/html/test1;
index index.php;
try_files $uri $uri/ =404;
}
location /test2{
root /var/www/html/test2;
index index.php;
try_files $uri $uri/ =404;
}
}
}
Related
Trying to configure my site to change root directory when there is a cookie var called "developer". This is on a Debian server.
This is my current site config file:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /sites/live/;
if ($http_cookie ~ 'developer') {
root /sites/dev/;
}
index index.php index.html index.htm index.nginx-debian.html;
server_name _;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
try_files $uri =404;
include /etc/nginx/fastcgi.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
}
But that gives me this error:
nginx: [emerg] "root" directive is not allowed here
What should I be doing? Thanks!
add root inside the location and the condition what you want
following is he my configuration working fine
location / {
root /var/www/myside;
index index.php;
try_files $uri $uri/ /index.php$is_args$args;
}
if that not work use rewrite rule
I would like to configure multiple websites on my nginx server. My configuration under /etc/nginx/sites-enabled/default is as below :
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /var/www/html/MyWebsite;
location / {
try_files $uri $uri/ =404;
}
location /admin {
alias /var/www/html/MyWebsiteAdmin;
try_files $uri $uri/ =404;
}
}
My website is deployed at www.mywebsite.com. I am able to access www.mywebsite.com but not able to access www.mywebsite.com/admin due to few errors like, it cannot load js and css files eg: www.mywebsite.com/inline.bundle.js, www.mywebsite.com/theme.css etc. So, It is trying to access js and css files from www.mywebsite.com but not from www.mywebsite.com/admin/inline.bundle.js. How can i resolve this issue?
/admin are folder then you not need
location /admin {alias /var/www/html/MyWebsiteAdmin;try_files $uri $uri/ =404;}
now /admin is like www.mywebsite.com/index.php/admin then you have to add rewrite rule of index.php
location / {index index.html index.php;try_files $uri $uri/ #handler;}location #handler { rewrite / /index.php; }
this is my site .conf file:
server {
listen [::]:80;
listen 80;
root /usr/share/nginx/html/suitecrm/;
index index.php index.html index.htm;
access_log /var/log/nginx/suitecrmaccess.log;
error_log /var/log/nginx/suitecrmerror.log error;
# Block access to stuff in the root
location ~* \.(pl|cgi|py|sh|lua|log|md5)$ {
return 444;
}
# Block access to data folders
location ~ /(soap|cache|upload|xtemplate|data|examples|include|log4php|metadata|modules|diagnostic|blowfish|emailmandelivery)/.*\.(php|pl|py|jsp|asp|sh|cgi|tpl|log|md5)$ {
return 444;
}
location / {
try_files $uri $uri/ =404;
index index.html index.htm index.php;
}
location ~ \.php$ {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
}
The paths are correct, I don't get what could be wrong here, any ideas please?
Have you looked at the suitecrm.log file to see what it says?
What I'm trying to achieve is if someone visit my home/index page, I need to server my index.html file. But, if it's another URL/path pass the request to my index.php file (I'm using Symfony).
I follow this example, but is not working. It's always serving my PHP file.
server
{
listen 80;
server_name mysite.com;
root /path/to/my/web;
index index.html index.php;
location = /index.html
{
try_files $uri /index.html?$args;
}
location /
{
try_files $uri /index.php?$args;
}
}
I will appreciate any help or guidance you can share with me.
This finally worked for me:
server
{
listen 80;
server_name mysite.com;
root /path/to/my/web;
index index.html index.php;
location = /
{
try_files $uri /index.html?$args;
}
location /
{
try_files $uri /index.php?$args;
}
}
I still struggling with making mystaticusername variable user name. I mean when I have particular username /statisusername/ backend working properly on nginx. But how can I make my configuration for more users? Means use instead mystaticusername some redirection where each username will know login to backend.
How can I change my nginx configuration?
server {
server_name example.com www.example.com;
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/www;
charset utf-8;
index index.html index.php /index.php;
location = / {
rewrite ^ /index.php;
}
location / {
rewrite ^([^\.]*)$ /$1.php;
rewrite ^/([A-Za-z0-9_]+)$ /admin/index.php?q=$uri&$args;
}
location ~ \.php$ {
try_files $uri =404;
include fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
location /mystaticusername {
try_files $uri/ /admin/index.php?q=$uri&$args;
}
location = /mystaticusername/options {
try_files $uri $uri/ /admin/index.php?hotelname=$1&do=options;
}
}
Not much context given, so I'm just guessin... but looks like you could condense your location directives to 3 statements.
This will default to index.php, but in the case of example.com/mystaticusername if would try that url and since it does not exist (guessing) it would serve up /admin/index.php?q=$uri&$args. This would also allow urls like exmaple.com/about to resolve. Just make certain to not allow users to create a username of 'about'
location / {
try_files $uri $uri/ /admin/index.php?q=$uri&$args;
}
Not certain what your goal is, but this would get you example.com/mystaticusername/options to try serve up /admin/index.php?hotelname=$1&do=options
location ~* ^/[a-zA-Z0-9]*/options$ {
try_files $uri /admin/index.php?hotelname=$1&do=options;
}
Leave php as-is
location ~ \.php$ {
try_files $uri =404;
include fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}