I'm using nginx as web front-end and apache2 as web back-end. Apache runs several websites locally and nginx access them.
At the moment, different sub-domains are hosted, but I want to migrate them into a single one using http://my-single-domain.com/subdomain-alias thanks to nginx.
The root directory and the apache2 vhost port is different for each sub-domain (sounds obvious, doesn't it?).
I tried several configurations but I cannot get the resource being sent, i.e., the index html is sent but the resources are not found by the server (404 Not Found) despite the rule root being set.
I tried several solution such as:
location /alias1 { proxy_pass http://127.0.0.1:9095/; include /etc/nginx/proxy.conf; } or
location /alias1 { alias /alias1/; proxy_pass http://127.0.0.1:9095/; include /etc/nginx/proxy.conf; } or even
location /alias1/ { rewrite ^/alias1(/.*)$ $1 break; proxy_pass http://127.0.0.1:9095/; } or again
location /alias1/ { rewrite ^/alias1(/.*)$ $1 break; proxy_pass http://127.0.0.1:9095/; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } What is wrong with this setup? How to set nginx to retrieves assets from a specific root directory when the age /alias1/page is requested ?
Asked first on webmasters.stackexchange.com
---### /etc/nginx/proxy.conf proxy_redirect off; 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 https; #client_max_body_size 10m; #client_body_buffer_size 128k; proxy_connect_timeout 90; #proxy_send_timeout 90; proxy_read_timeout 90; proxy_buffers 32 4k;
/etc/nginx/nginx.conf
user www-data www-data; worker_processes 2; pid /var/run/nginx.pid; worker_rlimit_nofile 1024; events { worker_connections 512; } http { include /etc/nginx/mime.types; default_type application/octet-stream; sendfile "on"; tcp_nopush "on"; tcp_nodelay "on"; keepalive_timeout "65"; access_log "/var/log/nginx/access.log"; error_log "/var/log/nginx/error.log"; server_tokens off; types_hash_max_size 2048; include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*/*; } /etc/nginx/site-enable/single-domain.conf
server { listen 443; ssl on; ssl_certificate /etc/ssl/private/single-domain.com-with_chain.crt; ssl_certificate_key /etc/ssl/private/single-domain.com.key.pem; ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA'; ssl_prefer_server_ciphers on; ssl_dhparam /etc/ssl/private/dhparams.pem; server_name www.single-domain.com; location / { proxy_pass http://127.0.0.1:8090/; include /etc/nginx/proxy.conf; } location /alias/ { proxy_redirect off; proxy_http_version 1.1; proxy_pass http://127.0.0.1:8103/; proxy_set_header Host alias.single-domain.com; root /var/www/alias.single-domain.com; } location ~* \.(jpg|png|gif|jpeg|css|js|mp3|wav|swf|mov|doc|pdf|xls|ppt|docx|pptx|xlsx|otf|eot|svg|ttf|woff)$ { root /var/www/single-domain.com/public; proxy_buffering on; proxy_cache_valid 200 120m; expires 864000; } access_log /var/log/nginx/single-domain.com/www-access.log; error_log /var/log/nginx/single-domain.com/www-error.log; }
/img/logo.pngbut/alias1/img/logo.png. It could be sometimes nearly impossible./alias/-part-path of the asset itself ?!