I just set the nginx for a subdomain and even so I still get just the Welcome page.
Here is the code I set on nginx sites-available
server {
listen 80;
server_name sub.domain.ro;
rewrite ^ https://sub.domain.ro$request_uri? permanent;
}
server {
listen 443 ssl http2;
# ssl_certificate /etc/letsencrypt/live/testsite.com/fullchain.pem;
# ssl_certificate_key /etc/letsencrypt/live/testsite.com/privkey.pem;
# ssl_stapling on;
server_name sub.domain.ro;
root /var/www/sub.domain.ro;
location / {
try_files $uri /index.php?$args;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
Please let me know what I did wrong or what I forget here.
Related
I have 2 links: myserver.org and myserver.org/support
I need first link follow to /var/www/myserver.org and second to /var/www/support
My config now:
first file & link
server {
listen 80 default_server;
server_name groupmanager.org;
charset utf-8;
root /var/www/groupmanager.org;
index index.php;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
access_log /var/log/nginx/groupmanager.org_access.log;
error_log /var/log/nginx/groupmanager.org_error.log;
include /etc/nginx/templates/php-fpm.conf;
}
server {
listen 80;
server_name www.groupmanager.org;
rewrite ^(.*) http://groupmanager.org$1 permanent;
}
Second file & link:
server {
listen 80;
server_name 163.172.88.31/support;
charset utf-8;
root /var/www/support;
index index.php;
access_log /var/log/nginx/support_access.log;
error_log /var/log/nginx/support_error.log;
include /etc/nginx/templates/php-fpm.conf;
}
server {
listen 80;
server_name www.163.172.88.31/support;
rewrite ^(.*) http://163.172.88.31/support$1 permanent;
}
php-fpm.conf
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~ /\.ht {
deny all;
}
location ~* \.(gif|jpeg|jpg|txt|png|tif|tiff|ico|jng|bmp|doc|pdf|rtf|xls|ppt|rar|rpm|swf|zip|bin|exe|dll|deb|cur)$ {
expires 168h;
}
location ~* \.(css|js)$ {
expires 180m;
}
First link works fine, second - no. I see '403 Forbidden'
What is not rigth?
Permissions for folders are the same, I think, they are right.
For both /var/www/myserver.org and /var/www/support you have to make two separate nginx config file with two different roots and server names .
besides , if you just want to show two links you can setup nginx for one and link the second one with just an internal link ( if they are in the same page)
Try like this:
include /etc/nginx/default.d/*.conf;
server {
listen 80 default_server;
server_name myserver.org;
charset utf-8;
root /var/www/myserver.org;
index index.php;
include /etc/nginx/default.d/*.conf;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
in /etc/nginx/default.d/ directory , create a .config file test.config:
location myserver.org {
proxy_pass /myserver.org;
}
location myserver.org/support {
proxy_pass /var/www/support;
}
This works:
groupmanager.org.conf
server {
listen 80 default_server;
server_name groupmanager.org;
charset utf-8;
root /var/www/groupmanager.org;
index index.php;
location /support/ {
alias /var/www/support/;
index index.php;
access_log /var/log/nginx/support_access.log;
error_log /var/log/nginx/support_error.log;
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /var/www/$fastcgi_script_name;
}
}
access_log /var/log/nginx/groupmanager.org_access.log;
error_log /var/log/nginx/groupmanager.org_error.log;
include /etc/nginx/templates/php-fpm.conf;
}
server {
listen 80;
server_name www.groupmanager.org;
rewrite ^(.*) http://groupmanager.org$1 permanent;
}
php-fpm.conf
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~ /\.ht {
deny all;
}
location ~* \.(gif|jpeg|jpg|txt|png|tif|tiff|ico|jng|bmp|doc|pdf|rtf|xls|ppt|rar|rpm|swf|zip|bin|exe|dll|deb|cur)$ {
expires 168h;
}
location ~* \.(css|js)$ {
expires 180m;
}
I´m trying to setup nginx HTTPS on my host, but gets a error:
nginx: [emerg] "location" directive is not allowed here in /etc/nginx/conf.d/default.conf:7
nginx: configuration file /etc/nginx/nginx.conf test failed
Conf:
server {
listen 443 ssl;
server_name quickseed.me;
ssl_certificate /etc/letsencrypt/live/quickseed.me/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/quickseed.me/privkey.pem;
}
root /var/www/html/;
index index.php index.html index.htm index.nginx-debian.html;
location /phpmyadmin {
root /usr/share/;
index index.php;
try_files $uri $uri/ =404;
location ~ ^/phpmyadmin/(doc|sql|setup)/ {
deny all;
}
location ~ /phpmyadmin/(.+\.php)$ {
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
Does anybody have any idea on how to fix this issue?
You should put location under a server directive. Try this code.
server {
listen 443 ssl;
server_name quickseed.me;
ssl_certificate /etc/letsencrypt/live/quickseed.me/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/quickseed.me/privkey.pem;
root /var/www/html/;
index index.php index.html index.htm index.nginx-debian.html;
location /phpmyadmin {
root /usr/share/;
index index.php;
try_files $uri $uri/ =404;
}
location ~ ^/phpmyadmin/(doc|sql|setup)/ {
deny all;
}
location ~ /phpmyadmin/(.+\.php)$ {
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Hope it helps.
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.
I have two apps... wordpress and WHMCS (a billing app)
example.com is wordpress.
example.com/portal to be WHMCS.
On the nginx server here is how I have my folders
/example.com
|_ /wordpress
|_ /whmcs
root is wordpress, but when someone goes to /portal I want the root to be /whmcs instead.
I've tried both root and alias. I either get 404 or 403 forbidden.
Here is my current example.conf file
server {
listen 80;
server_name example.com www.example.com;
return 301 https://example.com$request_uri;
}
server {
listen 80;
listen 443 ssl;
server_name example.com;
ssl_certificate /etc/nginx/ssl.crt;
ssl_certificate_key /etc/nginx/ssl.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers 'AES128+EECDH:AES128+EDH';
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
root /usr/share/nginx/example/wordpress;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
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;
}
location ^~ /portal/index.php {
autoindex on;
alias /usr/share/nginx/example/portal;
}
}
The solution is not to share the php location.
server {
listen 80;
server_name example.com;
root /usr/share/nginx/example;
location / {
root /usr/share/nginx/example/wordpress;
try_files $uri $uri/ /index.php?$query_string;
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; }
}
location /portal {
error_page 404 = #whmcs; }
location #whmcs {
rewrite ^(.*)$ /portal/index.php last;
root /usr/share/nginx/example/portal;
try_files $uri $uri/ /index.php?$query_string; }
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'm trying to getting started with nginx. But I cant really understand what's going wrong with this code.
As you can see there are 2 domains:
mauromarano.it
dev.mauromarano.it
The first domains hosts a wordpress blog.
#####################
# mauromarano.it/ #
####################
server {
listen 80;
# listen [::]:80 default_server;
root /usr/share/nginx/mauromarano.it/public_html;
index index.html index.htm index.php;
# Make site accessible from http://localhost/
server_name mauromarano.it www.mauromarano.it;
access_log /usr/share/nginx/mauromarano.it/logs/access.log;
error_log /usr/share/nginx/mauromarano.it/logs/error.log;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ /index.html;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
location /blog {
try_files $uri $uri/ /blog/index.php?$args;
}
location /doc/ {
alias /usr/share/doc/;
autoindex on;
allow 127.0.0.1;
allow ::1;
deny all;
}
location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(/blog)(/.*)$;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/mauromarano.it/public_html$fastcgi_script_name;
fastcgi_index index.php;
include fastcgi_params;
}
}
#####################
# mauromarano.com #
####################
server {
listen 80;
# listen [::]:80 default_server;
root /usr/share/nginx/mauromarano.com/public_html;
index index.html index.htm index.php;
# Make site accessible from http://localhost/
server_name mauromarano.com www.mauromarano.com;
access_log /usr/share/nginx/mauromarano.com/logs/access.log;
error_log /usr/share/nginx/mauromarano.com/logs/error.log;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ /index.html;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
location /doc/ {
alias /usr/share/doc/;
autoindex on;
allow 127.0.0.1;
allow ::1;
deny all;
}
location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/mauromarano.com/public_html$fastcgi_script_name;
fastcgi_index index.php;
include fastcgi_params;
}
}
#####################
# dev.mauromarano.it/ #
####################
server {
listen 80;
# listen [::]:80 default_server;
root /usr/share/nginx/dev.mauromarano.it/public_html;
index index.html index.htm index.php;
# Make site accessible from http://localhost/
server_name dev.mauromarano.it www.dev.mauromarano.it;
access_log /usr/share/nginx/dev.mauromarano.it/logs/access.log;
error_log /usr/share/nginx/dev.mauromarano.it/logs/error.log;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ /index.html;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
location /doc/ {
alias /usr/share/doc/;
autoindex on;
allow 127.0.0.1;
allow ::1;
deny all;
}
location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(/blog)(/.*)$;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/dev.mauromarano.it/public_html$fastcgi_script_name;
fastcgi_index index.php;
include fastcgi_params;
}
}
Where I'm wrong?
My goal Is to having this two domains working. But in this way, the subdomains (dev.mauromarano.it) is not working.
The following clause is not needed for server blocks:
listen 80;
listen [::]:80 default_server;
This should solve the subdomain issue. In addition to this, you are missing the rewrite rules for wordpress. They should be as follows:
location / {
try_files $uri $uri/ #wordpress;
}
location #wordpress {
rewrite ^/(.*)$ /index.php?/$1 last;
}
Hopefully this will clear your problem. More info on it would mean more pointed solutions, however, so feel free to comment with any bugs you still have.