I have a Amazon EC2 Server setup with Nginx 1.8.1 on port 80 and Apache 2.4 on port 8080.
My Nginx error log is filled with invalid local address "www.domain.com:80"
Can someone advise how to fix this error?
My domain.com under /etc/nginx/sites-enabled is as below
server {
listen 80;
server_name domain.com www.domain.com;
root /home/domain/public_html/;
index index.php index.htm index.html;
location / {
#try_files $uri $uri/ /index.php;
#try_files $uri $uri/ $uri.php;
try_files $uri $uri/ /index.php?/$request_uri;
}
location ~ \.php$ {
proxy_bind $host:80;
proxy_pass http://www.domain.com:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
add_header X-Cache-Status $upstream_cache_status;
# Cache configuration
proxy_cache my-cache;
proxy_cache_valid 10s;
proxy_no_cache $cookie_PHPSESSID;
proxy_cache_bypass $cookie_PHPSESSID;
proxy_cache_key "$scheme$host$request_uri";
}
# Disable Cache for the file type html, json
location ~* .(?:manifest|appcache|html?|xml|json)$ {
expires -1;
}
# Enable Cache the file 30 days
location ~* .(jpg|png|gif|jpeg|css|mp3|wav|swf|mov|doc|pdf|xls|ppt|docx|pptx|xlsx)$ {
proxy_cache_valid 200 120m;
expires 30d;
proxy_cache my-cache;
#access_log off;
add_header X-Cache-Status $upstream_cache_status;
}
location ~ /\. {
access_log off;
log_not_found off;
deny all;
}
}
My domain.com under Apache Virtual Host is as below
<VirtualHost 172.31.xx.xxx:8080>
DocumentRoot /home/domain/public_html/
ServerName domaine.com
ServerAlias www.domain.com n1.domain.com
ErrorLog /home/domain/logs/error_log
CustomLog /home/domain/logs/access_log combined
<Directory /home/domain/public_html>
Options -Includes -ExecCGI
AllowOverride All
</Directory>
Is there any particular reason as to why you have the proxy_bind $host:80; directive? If not, remove it and it should stop the error (note that the address that you're binding to must be local, if you chose to go that route).
Related
I thought that i have only apache on my server, but i see that nginx catches some query's before apache do...
my .htaccess file:
RewriteEngine On
RewriteRule ^.*$ index.php [NC,L]
But when i go to url like
https://site.domain/folder/another/folder/file.png
I get 404 error, instead of result of my index.php-script!
I tried to change my nginx-config by many ways so it was in vain.
There is it:
server {
server_name site.domain www.site.domain;
charset off;
index index.html index.php;
disable_symlinks if_not_owner from=$root_path;
include /etc/nginx/vhosts-includes/*.conf;
include /etc/nginx/vhosts-resources/site.domain/*.conf;
access_log /var/www/httpd-logs/site.domain.access.log;
error_log /var/www/httpd-logs/site.domain.error.log notice;
ssi on;
return 301 https://$host:443$request_uri;
set $root_path /var/www/www-root/data/www/site.domain;
root $root_path;
location / {
location ~ [^/]\.ph(p\d*|tml)$ {
try_files /does_not_exists #fallback;
}
location ~* ^.+\.(jpg|jpeg|gif|png|svg|js|css|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar|swf)$ {
try_files $uri $uri/ #fallback;
}
location / {
try_files /does_not_exists #fallback;
}
}
location #fallback {
proxy_pass http://127.0.0.1:8080;
proxy_redirect http://127.0.0.1:8080 /;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Port $server_port;
access_log off;
}
listen 77.777.7.777:80;
}
server {
server_name ege2018.top www.site.domain;
ssl_certificate "/var/www/httpd-cert/www-root/site.domain_le1.crtca";
ssl_certificate_key "/var/www/httpd-cert/www-root/site.domain_le1.key";
ssl_ciphers EECDH:+AES256:-3DES:RSA+AES:!NULL:!RC4;
ssl_prefer_server_ciphers on;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_dhparam /etc/ssl/certs/dhparam4096.pem;
charset off;
index index.html index.php;
disable_symlinks if_not_owner from=$root_path;
include /etc/nginx/vhosts-includes/*.conf;
include /etc/nginx/vhosts-resources/site.domain/*.conf;
access_log /var/www/httpd-logs/site.domain.access.log;
error_log /var/www/httpd-logs/site.domain.error.log notice;
ssi on;
set $root_path /var/www/www-root/data/www/site.domain;
root $root_path;
location / {
location ~ [^/]\.ph(p\d*|tml)$ {
try_files /does_not_exists #fallback;
}
location ~* ^.+\.(jpg|jpeg|gif|png|svg|js|css|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar|swf)$ {
try_files $uri $uri/ #fallback;
}
location / {
try_files /does_not_exists #fallback;
}
}
location #fallback {
proxy_pass http://127.0.0.1:8080;
proxy_redirect http://127.0.0.1:8080 /;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Port $server_port;
access_log off;
}
listen 77.777.7.777:443 ssl;
}
(I changed-to-hide domain name and server ip)
Please, help me to solve this problem, i hope it's possible just by editing nginx-config.
Thank you!
Have you got access to both nginx and Apache HTTPd logs? tail -F both log files while you access the URL. #fallback does indeed look like it sends the request to HTTPd if it cannot find it locally, does the request get to the HTTPd log? You may find that index.php isn't where HTTPd is expecting to find it.
My bad! I changed-to-hide actually url, which i want to visit, but key was there.
The url was like
site.domain/icons/...
And apache go to his own icons folder despite .htaccess instructions...
I touched apache config to solve this problem - commented alias for /icons/
I'm learning NGINX and I need to set a frontend webserver with NGINX and a backend webserver with Apache using .htaccess
This is the content of /etc/nginx/sites-available/my_test5.loc
server {
charset utf-8;
client_max_body_size 128M;
listen 80;
server_name my_test5.loc;
root /var/www/my_test5.loc/web;
#root /var/www/my_test5.loc;
index index.php;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
# deny accessing php files for the /assets directory
location ~ ^/assets/.*\.php$ {
deny all;
}
location ~ \.php$ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:8080;
}
location ~* /\. {
# deny all;
allow all;
}
}
This is the content of /etc/apache2/sites-available/my_test5.loc.conf
<VirtualHost *:8080>
<Directory /var/www/my_test5.loc/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ServerAdmin admin#my_test5.loc
ServerName my_test5.loc
ServerAlias www.my_test5.loc
DocumentRoot /var/www/my_test5.loc/web/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Now all I have working is the main page. If I try to navigate to site/about for example I can't. What have I done wrong and how to use these 2 web servers?
I think your setup is only pointing correctly into index.php because of your location / {} directive, try editing your to be more permissive about your Apache access changing this block to pass through it and adding specific block to other kind of files, like assets.
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:8080;
}
location ~* \.(jpg|jpeg|png|gif|ico|css|js|ttf|ttc|otf|eot|woff|woff2)$ {
try_files $uri $uri/
}
This way NGINX serves your static files and Apache serves everything else.
For Nginx work
use .htaccess for apache
siteName.conf apache must be
siteName conf must be in nginx sites-available and sites-enable
be sure that you send request from 80 port to 8080(as in my case) and Apache are listening it
I am trying to insert a new website in a digital ocean server. There are currently 4 websites being hosted there in Nginx. I've created a Nginx Virtual Host that works as a reverse proxy for Apache, which is listening in the port 8000. It is currently redirecting when I try to access the domain, but it is failing to load all the CSS and Javascript. It just loads the HTML. But if I access it through www.domain.com:8000 it loads perfectly.
The Nginx configuration file for the website:
server {
listen 80;
root /usr/share/nginx/html/;
index index.php index.html index.htm;
server_name example.com www.example.com;
location / {
try_files $uri $uri/ /index.html?$args;
# include /etc/nginx/mime.types;
}
# location ~* .(jpg|jpeg|png|gif|ico|css|js)$ {
# expires 1s;
# }
location ~ \.css {
add_header Content-Type text/css;
}
location ~ \.js {
add_header Content-Type application/x-javascript;
}
location ~ \.html$ {
include /etc/nginx/mime.types;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://example.com:8000;
}
location ~ /\.ht {
deny all;
}
}
The Apache .conf file:
Listen 8000
<VirtualHost *:8000>
ServerAdmin admin#gmail.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
I don't use PHP on the website, just HTML, CSS and JavaScript.
ok
now i installed laravel 4.2 on ubuntu 14.4 with apache and nginx proxy .
and when i create route like
Route::get('/reg', function()
{
return 'hii';
});
apache view "hii" when i call "localhost:8080/reg"
but nginx view main page when i call "localhost/reg" in browser
the nginx config :
server {
listen 80;
root /var/www/laravel/public;
index index.php index.html index.htm;
server_name localhost;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
if (!-d $request_filename) {
rewrite ^/(.+)/$ /$1 permanent;
}
location ~ \.php$ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:8080;
}
# PHP FPM configuration.
location ~* \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script$
}
location ~ /\.ht {
deny all;
}
}
where is wrong ?
According to your nginx.conf, It's loading your /var/www/laravel/public/index.php;. If you don't want that to happen,
adjust the path in nginx.conf to the file you want to load,
OR
make a view, and then point the path to that view.
I'm trying to get the https working with some urls. but it seems that the https goes everywhere. In details, I have created 2 vhosts on Nginx. The first virtual host with port 80 and the other one with 443 containing SSL. now my site .i.e domain.com works for both http and https and this is not what I want. I want the https working on one some urls I specify with rules in Nginx vhost.
The main issue is when I try that I get my main site first with http then when I go to a url that contains https "secure_area", it works fine. However, whenever I go after that somewhere else in my site, the https keep going on all other urls.
here is my 443 vhost config:
ssl_session_cache shared:SSL:5m;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains";
server {
listen 443 ssl spdy;
listen [::]:443 ssl spdy;
#server_name www.mydomain.com;
ssl_session_timeout 5m;
root /vars/www/public_html/;
index index.php index.html index.htm;
ssl_certificate /path_to_ssl/certificate.pem;
ssl_certificate_key /path_to_key/server.key;
ssl_ciphers 'ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS';
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
location / {
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:8080;
}
location ~ /\.ht {
deny all;
}
# Serve static files directly
location ~* \.(png|jpe?g|gif|ico)$ {
expires 1y; access_log off; try_files $uri $uri/ #rewrite; gzip off;
}
location ~* \.(css)$ {
expires 1d; access_log off;
}
location ~* \.(js)$ {
expires 1h; access_log off;
}
location /secure_area/ {
auth_basic "Restricted";
auth_basic_user_file htpasswd;
rewrite ^ https://$http_host$request_uri? permanent;
}
}
and here is my 80 vhost config:
server {
listen 80 default_server;
server_name mydomain.com;
return 301 http://www.mydomain.com;
}
server {
listen 80;
server_name www.mydomain.com;
root /vars/www/public_html/;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:8080;
}
location ~ /\.ht {
deny all;
}
location /secure_area/ {
rewrite ^ https://$http_host$request_uri? permanent;
}
}
in case no one noticed, Nginx is working as reverse proexy at front end Apache
now does anyone have any idea how to force https only on some urls and in my case secure_area and force http on all other urls?
Thanks
You can tell the SSL server to redirect back to http if any other URL is visited
server {
listen 80;
server_name example.com;
# normal http settings
location /secure_area/ {
return 301 https://$http_host$request_uri$is_args$query_string;
}
}
server {
listen 443 ssl spdy;
server_name example.com;
# ssl settings;
location /secure_area/ {
#serve secure area content
}
location / {
return 301 http://$http_host$request_uri$is_args$query_string;
}
}