Answer the question
In order to leave comments, you need to log in
How to set up Nginx for a separate project when Apache is already installed?
Lord good day!
Baffled by this situation.
Previously, I worked with projects on php frameworks, I have them in /var/www/html and for each I select a separate port in the Apache settings, like this:
in etc/apache2/sites-available/000-default.conf I attribute:
ServerAdmin [email protected]
DocumentRoot /var/www/html/projectname
ErrorLog ${APACHE_LOG_DIR}/error-projectname.log
CustomLog ${APACHE_LOG_DIR}/access-projectname.log combined
and added to /etc/apache2/ports.conf
Listen 85
And then adjusted the work with js. I see the nginx.conf file in the root, I realized that I need to install it.
I googled several articles on setting up nginx + apache, I try to set it up - it doesn't work.
I see the process itself like this: I put the project in the /var/www/html folder, out of habit I select a separate port in the Apache settings (for example, VirtualHost *: 85), and then I also configure nginx specifically for it.
In some articles it is written about setting /etc/nginx/sites-available/default
In some articles about setting /etc/nginx/nginx.conf.
I tried with /etc/nginx/nginx.conf
I don't understand what to write in the server if I have a separate port 85 allocated for this in the Apache settings?
server {
client_max_body_size 10M;
listen 85;
server_name myproject; <--- put name here? or localhost:85? or you can not specify at all?
}
here
location / {
proxy_pass 127.0.0.1:8080/;<-- change this value?
What to do with /etc/nginx/sites-available/default? I understand that you need to copy it and rename it to /etc/nginx/sites-available/myproject? and write settings for your project like
server {
listen 85;
server_namemyproject;
access_log /home/example/logs/myproject_nginx_access.log;
error_log /home/example/logs/myproject_nginx_error.log;
location ~* \.(jpg|jpeg|gif|png|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|tar|wav|bmp|rtf|swf|ico|flv| txt|docx|xlsx)$ {
root /home/example/www/; <----here to write the folder where I put the project?
index index.html index.php; <------ is it necessary to specify the start page?
access_logoff;
expires 30d;
}
location ~ /\.ht {
deny all;
}
location / {
proxy_pass 127.0.0.1:8080/; <-----------I don't understand if I need to change the port here?
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-for $remote_addr;
proxy_set_header Host $host;
proxy_connect_timeout 60;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_redirect off;
proxy_set_header Connection close;
proxy_pass_header Content-Type;
proxy_pass_header Content-Disposition;
proxy_pass_header Content-Length;
}
}
My head is full of mess right now. Help me to understand.
Answer the question
In order to leave comments, you need to log in
Are you trying to force apache and nginx to listen on the same port, and which one will then have to return the content when requested?
The request should be received by nginx on the port you need (85), and then in proxy_pass address it to the port on which apache is located (any other, for example 86).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question