Detailed Nginx and Apache 80-port configuration method _nginx

Source: Internet
Author: User
Tags zend

A typical Nginx + Apache application can be Nginx to occupy 80 ports, filter static requests, and then dynamically request Proxy to Apache's 8080 port. The advantage of proxy reverse proxy is that when you visit, it is always 80 ports, and visitors will not be aware of any difference.

But some applications are very "smart", the identification of Apache is located in the port is 8080, will be associated with hyperlinks are added: 8080 follow-up. So you're dead, and you can have regular access?!

One way to solve this problem is to run Apache on port 80 as well. The same server, there are nginx also have apache,2 a httpd service, are 80, not conflict?

The bottom is the example method.
In the configuration of nginx.conf

server {
 listen;
 server_name www.webyang.net;
}

Modify it.

server {
 listen 192.168.3.3:80;  #指定Nginx只占用某个IP的80端口.
 Listen 192.168.10.3:80;  #如果你服务器中有多个IP, you can also specify multiple.
 server_name www.webyang.net;
}

If you have multiple virtual hosts in Nginx, each one needs to be modified.

And then the httpd.conf of Apache.
Put the original

Listen 80

To

Listen 127.0.0.1:80

As with Nginx, specify the IP and port that Apache uses.
Save exit, restart Apache to take effect.
If you have more than one virtual host on Apache. There is no need to modify it as nginx, as long as it is 80 ports.

Such as:

Namevirtualhost *:80
<virtualhost *:80>
 ServerAdmin hello@abc.com
 Admin
 ServerName www.webyang.net
</VirtualHost>

Do you think it's all over? Not too.

Such Apache can only be accessed through http://127.0.0.1:80, so it doesn't make sense for him to occupy 80 ports. Not as good as Apache with 8080,nginx 80.
So at this point if your server has more than IP, in addition to the Apache binding in the 127.0.0.1 can also bind another net card IP, then solve the problem.

But the average person is only one independent IP, so this method for many people is a mirage.
Modify a thought, Apache or 8080 port, modify one of the Nginx domain name conf file

Location/{
 try_files $uri @apache;
}
 
Location @apache {
 internal;
 Proxy_pass http://127.0.0.1:8080;
}
 
Location ~. *. (PHP|PHP5)? $ {
 Proxy_pass http://127.0.0.1:8080;
}

At this point, all the actions of the domain name go to Apache, including static files.

There are also a lot of people who are writing the following:

Upstream Zend {
 server 127.0.0.1:8080;
}
 
Location/{
 proxy_pass  http://zend;
 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-scheme $scheme;
}
 
Location ~. *. (PHP|PHP5) $ {
 proxy_pass  http://zend;
 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-scheme $scheme;
}

Broadly similar.

Port modification for Nginx
Modify the nginx.conf file implementation. On Linux the path to the file is/usr/local/nginx/conf/nginx.conf,windows under install directory \conf\nginx.conf.

server {
 listen  ;
 server_name localhost;
 
 ...
}

Change into

server {
 listen  Bayi;
 server_name localhost;
 
 Location/{
 root html;
 Index index.html index.htm;
 }
 ...
}

Of course it can be changed to 8080,8081, not necessarily 81, but make sure iptable to open access to the port.

Note the configuration of the location:

root HTML; #根目录, relative to the installation directory 
index index.html index.htm; #默认主页

By default, you place the file in the HTML folder under the installation directory, and you can access it via Nginx.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.