I want to have two servers on my machine, one private, accessible only locally on 127.0.0.1 and one which is visible on LAN (it's root folder is subfolder of the private server). So I have made two configuration files in sites-available and linked them to sites-enabled folder. File accessible:
server {
listen 80;
root /usr/share/nginx/html/accessible/;
index index.php index.html index.htm;
server_name accessible;
location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html/accessible/;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
and file localhost:
server {
listen 127.0.0.1:80;
listen [::1]:80;
root /usr/share/nginx/html;
index index.php index.html index.htm;
server_name localhost;
location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
After that I have updated /etc/hosts so that http://accessible/ is forwarded to 127.0.0.1: 127.0.0.1 accessible is the line.
Now when I try to connect to http://localhost/, everything is ok, I get /usr/share/nginx/html/index.html as expected. But when I try to connect to http://accessible/ The same file /usr/share/nginx/html/index.html is displayed. How is that possible? The root folders are apparently set.
The problem is that localhost server operates on the same IP as I have configured for accessible to be redirected to which is apparently not possible (or at least I don't know how).
I have redirected accessible to 127.0.0.2 (changed line in /etc/hosts to 127.0.0.2 accessible) which is another address served by local machine and after small change in nginx config file accessible that allowed all LAN IP addresses (allow 192.168.1.0/32;) everything works just fine (for me on local machine and for computers on network).
Related
I want to add a domain manually with cli of centos 7 and created a config file in sites-available directory:
server {
listen 80;
server_name hustana.ir www.hustana.ir;
location / {
root /home/www/public_html;
index index.html index.htm;
try_files $uri $uri/ =404;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
In my server there is another domains that are online and works fine.
if its help I should tell that at start my server was worked by Plesk Obtisian control panel
but now I wanna add another domain to server just but it`s not working.
I changed my domain NS from domain control center.
additional description:
I guess it`s good to say that if I delete the config block of one of my older domains , domain still stay online but it displays just a blank white page.
I tried add to include this config file from another directory directly into nginx.conf:
server {
listen 80;
server_name hustana.ir;
root /home/www/public_html;
index index.php;
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;
}
}
You need to enable your site as mentioned here.
Check the A-record of your domain. It must point to your server IP.
I install nginx 1.13.10 with a wordpress site and openssl on my virtual machine. I'm trying to test http2 push. Here is my nginx conf file:
pastebin.com/71ziXeRh
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name 192.168.133.21;
return 302 https://$server_name$request_uri;
}
# Load configuration files for the default server block.
server {
listen 443 ssl http2;
server_name 192.168.133.21;
include conf.d/self-signed.conf; #ssl config
ssl on;
location / {
root /var/www/wordpress/current;
index index.php index.html index.htm;
http2_push /wp-content/themes/twentyseventeen/assets/images/header.jpg;
http2_push /wp-content/themes/twentyseventeen/style.css?ver=4.7.4;
}
error_page 404 /404.html;
location = /40x.html {
root /usr/share/nginx/html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
root /var/www/wordpress/current;
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;
}
}
Restart nginx and no error. But when I debug it with Chrome no resource was pushed demo image
Please tell me if I do something wrong somewhere.
It's a restriction in Chrome. If your SSL/TLS cert is not trusted (as we can see yours is not in the screenshot) it ignores pushed resources. Even if you skip paste the HTTPS error. Similarly resources on such a site cannot be cached.
Add the certificate to your browser's trust store so you get a green padlock and it should start to work.
Similar question (but using Node rather than Nginx) here.
Installation
OS: CentOS 7.4
Server: Nginx 1.12.2
Question: My nginx installation serves files without problem from the default directory, /usr/share/nginx/html. Unfortunately I get a 403 error when I use a new folder that I created, /www/html. What should I look for?
My permissions are identical for both folders although the owner is different.
Original default folder
drwxr-xr-x. 13 root root 155 Jan 8 09:25 usr
New default folder
drwxr-xr-x. 3 first first 18 Jan 15 10:45 www
I am using the stripped down server.conf file below and it works correctly.
events {}
http {
server {
listen 80;
server_name mydomain.com;
root /usr/share/nginx/html;
}
}
However when I change server.conf to use this directory /www/html I get a 403 error.
Thanks for any help in advance! I'm a noob and not even sure where to look beyond file permissions.
I faced the same problem.
Solution. You must create test.example.com.conf inside the conf.d folder
sudo nano /etc/nginx/conf.d/test.example.com.conf
And the file :
server {
listen 80;
#listen *:80;
server_name test.example.com;
# note that these lines are originally from the "location /" block
root /var/www/test.example.com/;
index index.html index.htm index.php;
location / {
try_files $uri $uri/ /index.php?$args;
}
# Remove trailing slash to please routing system.
if (!-d $request_filename) {
rewrite ^/(.+)/$ /$1 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/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
restart server systemctl restart nginx.service
In Apache (without mod_rewrite) I could utilize URI's such as this:
/module/erp/service.php/application/workorder/list?start=0&limit=25
What do I have to configure or change to support this with NGINX?
server {
listen 80;
root /usr/share/nginx/www/web/public;
index index.php index.html;
server_name apps.mydomain.com;
location / {
try_files $uri $uri/ /index.html;
}
#error_page 404 /404.html;
#error_page 500 502 503 504 /50x.html;
#location = /50x.html {
# root /usr/share/nginx/www;
#}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
Can someone show me what I might need to add in order to achieve this requirement?
p.s-I need to populate the $_SERVER['PATH_INFO'] just as Apache does as well...
EDIT |
I believe I found my answer here:
https://askubuntu.com/questions/164627/nginx-php-fpm-access-denied-error
I then encountered "access denied" which sounds like the resolve is here:
https://askubuntu.com/questions/164627/nginx-php-fpm-access-denied-error
Any ideas???
OK the links I provided above walked me through the process of resolving my issue with odd URI configuration.
The issue was the cgi.fix_pathinfo=0
Most articles I read suggest this is a gapping security hole -- in the case where one might have uploads. I do not have uploads enabled.
http://wiki.nginx.org/PHPFcgiExample
Security trade-off? Perhaps...in my case it wasn't as important as the URI handling as Apache did.
First off, first time nginx user. So, I'm still learning the differences from Apache and nginx.
I have a stock install of nginx. (apt-get install nginx-full) I modified the default configuration found at '/etc/nginx/sites-enabled/default' for my setup. However, error pages just don't work. My docroot is /server/www, and my error pages are located within the directory /server/errors/. Below is my config.
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /server/www;
index index.html;
server_name website.com;
location / {
try_files $uri $uri/ /index.html;
}
error_page 403 404 405 /40x.html;
location /40x.html {
root /server/errors;
internal;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /server/errors;
internal;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
All pages that should generate a 403 or 404 page, just load the index.html file. I believe the something is probably happening with 500 errors, however, that's a bit harder to generate.
Also, if it's relevant, I moved the error pages above docroot, but they weren't working before that. I made that move as the 'internal' flag didn't appear to make the pages internal as the documentation claimed, as I could still access them directly.
Any advise/help you could give would be great!
The error issue was related to the location / having an end value of /index.html. Essentially, nginx was first trying the uri as a file, then as a directory, and then reverting to index.html. Instead I wanted it to return a 404. So I changed it to the below and now it works.
location / {
try_files $uri $uri/ =404;
}