M
M
matveyboyko2017-10-06 12:37:27
Nginx
matveyboyko, 2017-10-06 12:37:27

How to set up nginx+apache2 on Debian 8?

Greetings!
There is a home server at: http://sgus.ddns.net:61840
Port 61840 forwarded to 80th.
It costs apache and the site works.

netstat -tulpn | grep :8
tcp6       0      0 :::80                   :::*                    LISTEN      3350/apache2

There was a need for security and performance reasons to install nginx as a front-end to Apache.
My actions.
1. Translated Apache to wiretap the 81st port:
nano /etc/apache2/ports.conf
# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default.conf

NameVirtualHost 127.0.0.1:81
Listen 81

<IfModule ssl_module>
        Listen 443
</IfModule>

<IfModule mod_gnutls.c>
        Listen 443
</IfModule>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

netstat -tulpn | grep :8
tcp6       0      0 :::81                   :::*                    LISTEN      3471/apache2

2. Installed nginx, cat. By default, it listens on port 80.
3. Created an html.conf file in the cd /etc/nginx/sites-available directory:
server {
    listen *:80;
    server_name html;

    location / {
        proxy_pass http://127.0.0.1:81/;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_connect_timeout 120;
        proxy_send_timeout 120;
        proxy_read_timeout 180;
    }

    location ~* \.(jpg|jpeg|gif|png|ico|css|bmp|swf|js|html|txt)$ {
        root /var/www/html; 
    }
}

4. Actually, as you can see from the config, in the /var/www/html directory there is an installed and deployed site on Prestashop (it works fine with bare Apache).
5. The contents of the file /etc/apache2/sites-available/000-default.conf:
<VirtualHost 127.0.0.1:81>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com

        ServerAdmin [email protected]
        DocumentRoot /var/www/html

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

6. Nginx and apache are restarted.
If you haven't forgotten anything, that's all.
I get an error: "403 Forbidden
nginx/1.6.2".
Point in the right direction, what did you miss or do wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
chupasaurus, 2017-10-06
@chupasaurus

Vanga mod: nginx or apache does not have access to files in /var/www/html/. The exact reason is in the nginx logs.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question