How to start nginx via different port(other than 80)

前端 未结 5 894
梦如初夏
梦如初夏 2020-11-28 01:36

Hi I am a newbie on nginx, I tried to set it up on my server(running Ubuntu 4), which already has apache running.

So after I apt-get install it, I trie

相关标签:
5条回答
  • 2020-11-28 01:46

    If you are on windows then below port related server settings are present in file nginx.conf at < nginx installation path >/conf folder.

    server {
        listen       80;
        server_name  localhost;
    ....
    

    Change the port number and restart the instance.

    0 讨论(0)
  • 2020-11-28 01:52

    If you are experiencing this problem when using Docker be sure to map the correct port numbers. If you map port 81:80 when running docker (or through docker-compose.yml), your nginx must listen on port 80 not 81, because docker does the mapping already.

    I spent quite some time on this issue myself, so hope it can be to some help for future googlers.

    0 讨论(0)
  • 2020-11-28 01:57

    Follow this: Open your config file

    vi /etc/nginx/conf.d/default.conf
    

    Change port number on which you are listening;

    listen       81;
    server_name  localhost;
    

    Add a rule to iptables

     vi /etc/sysconfig/iptables 
    -A INPUT -m state --state NEW -m tcp -p tcp --dport 81 -j ACCEPT
    

    Restart IPtables

     service iptables restart;
    

    Restart the nginx server

    service nginx restart
    

    Access yr nginx server files on port 81

    0 讨论(0)
  • 2020-11-28 01:58

    You have to go to the /etc/nginx/sites-enabled/ and if this is the default configuration, then there should be a file by name: default.

    Edit that file by defining your desired port; in the snippet below, we are serving the Nginx instance on port 81.

    server {
        listen 81;
    }
    

    To start the server, run the command line below;

    sudo service nginx start
    

    You may now access your application on port 81 (for localhost, http://localhost:81).

    0 讨论(0)
  • 2020-11-28 02:08

    You will need to change the configure port of either Apache or Nginx. After you do this you will need to restart the reconfigured servers, using the 'service' command you used.


    Apache

    Edit

    sudo subl /etc/apache2/ports.conf 
    

    and change the 80 on the following line to something different :

    Listen 80
    

    If you just change the port or add more ports here, you will likely also have to change the VirtualHost statement in

    sudo subl /etc/apache2/sites-enabled/000-default.conf
    

    and change the 80 on the following line to something different :

    <VirtualHost *:80>
    

    then restart by :

    sudo service apache2 restart
    

    Nginx

    Edit

    /etc/nginx/sites-enabled/default
    

    and change the 80 on the following line :

    listen 80;
    

    then restart by :

    sudo service nginx restart
    
    0 讨论(0)
提交回复
热议问题