I
I
Ilia Malashko2020-02-13 13:14:39
linux
Ilia Malashko, 2020-02-13 13:14:39

How to set up nginx + apache and nginx + php-fpm bundles on the same server?

Hello!

The task is to work from one server site1.ru on a bunch of nginx + apache, and site2.ru on nginx + php-fpm.
For some reason I couldn't google the answer to my question.

I planned to listen to port 80 with nginx, then send site1.ru to :8080, :8080 will listen to apache, and send site2.ru to :8081 where it will listen to php-fpm

Configured nginx + apache on both domains without problems.
I tried to connect nginx + php-fpm for site2.ru, read the documentation and ran into the problem that nginx does not send via locahost to another port, but everything is configured in the nginx config.
I set it up according to the instructions and now I have both site1.ru and site2.ru giving content from site1.ru

Share who can give instructions on this problem.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sanes, 2020-02-13
@Sanes

<VirtualHost 127.0.0.1:8080>
    ServerName {{ username }}.loc
    ServerAlias {{ domains }}
    # ServerAlias example.*.xip.io

    DocumentRoot /home/{{ username }}/www

    <Directory /home/{{ username }}/www>
        Options -Indexes +FollowSymLinks +MultiViews
        AllowOverride All
        Require all granted
    </Directory>

    <FilesMatch \.php$>
        # 2.4.10+ can proxy to unix socket
        SetHandler "proxy:unix:/var/run/php/php{{ php }}-fpm-{{ username }}.sock|fcgi://localhost/"

        # Else we can just use a tcp socket:
        # SetHandler "proxy:fcgi://127.0.0.1:9000"
    </FilesMatch>

    ErrorLog ${APACHE_LOG_DIR}/{{ username }}-error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    # CustomLog ${APACHE_LOG_DIR}/example.com-access.log combined

</VirtualHost>

D
Dmitry Derepko, 2020-02-13
@xEpozZ

Why php-fpmassign port 8081? He and 9000 works fine.
Show me your configs.
> read the documentation and ran into a problem that nginx does not send via locahost to another port
It's not entirely clear what you mean. For php-fpmthere is fastcgia module.
Wangyu what have you lostserver_name site1.ru;

V
Victor Taran, 2020-02-13
@shambler81

you have three files
1. common which for unsorted requests is essentially a trash can, the first site usually hangs on it, but this is wrong because it’s just ALL domains, that is, exactly what leads you to hello on the server.
2. You have two configs in which hosts are explicitly registered and a proxy is specified in one of them, and FPM in the second
3. You have ssl issued for each site, you cannot issue ssl to one site (SSL connection specifics) if at least one has it site, it appears on the rest. BUT this is a separate topic.
And so
1. Delete the default config, you don't need it
2. delete the default one for ssl because it will only interfere
3. issue keys for each site
4. Specify proxy in one file
5. Specify FPM in another file
6. if you have ssl configs in separate files ,
for example
site1.ru_ssl.conf, then change all the settings in them too.
And everything will work for you

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question